1// Copyright 2014 The Chromium Authors. All rights reserved. 2// Use of this source code is governed by a BSD-style license that can be 3// found in the LICENSE file. 4 5#include "chrome/browser/android/meta_tag_observer.h" 6 7#include "chrome/common/chrome_constants.h" 8#include "chrome/common/render_messages.h" 9#include "content/public/browser/render_frame_host.h" 10#include "content/public/browser/web_contents.h" 11#include "content/public/browser/web_contents_observer.h" 12 13MetaTagObserver::MetaTagObserver(const std::string& meta_tag) 14 : meta_tag_(meta_tag) { 15 if (meta_tag_.size() > chrome::kMaxMetaTagAttributeLength) { 16 VLOG(1) << "Length of the <meta> name attribute is too large."; 17 NOTREACHED(); 18 } 19} 20 21MetaTagObserver::~MetaTagObserver() { 22} 23 24void MetaTagObserver::DidFinishLoad(content::RenderFrameHost* render_frame_host, 25 const GURL& validated_url) { 26 if (render_frame_host->GetParent()) 27 return; 28 validated_url_ = validated_url; 29 Send(new ChromeViewMsg_RetrieveMetaTagContent(routing_id(), 30 validated_url, 31 meta_tag_)); 32} 33 34bool MetaTagObserver::OnMessageReceived(const IPC::Message& message) { 35 bool handled = true; 36 IPC_BEGIN_MESSAGE_MAP(MetaTagObserver, message) 37 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_DidRetrieveMetaTagContent, 38 OnDidRetrieveMetaTagContent) 39 IPC_MESSAGE_UNHANDLED(handled = false) 40 IPC_END_MESSAGE_MAP() 41 return handled; 42} 43 44void MetaTagObserver::OnDidRetrieveMetaTagContent( 45 bool success, 46 const std::string& tag_name, 47 const std::string& tag_content, 48 const GURL& expected_url) { 49 if (!success || tag_name != meta_tag_ || validated_url_ != expected_url || 50 tag_content.size() >= chrome::kMaxMetaTagAttributeLength) { 51 return; 52 } 53 HandleMetaTagContent(tag_content, expected_url); 54} 55