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_view_host.h" 10 #include "content/public/browser/web_contents.h" 11 #include "content/public/browser/web_contents_observer.h" 12 13 MetaTagObserver::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 21 MetaTagObserver::~MetaTagObserver() { 22 } 23 24 void MetaTagObserver::DidFinishLoad( 25 int64 frame_id, 26 const GURL& validated_url, 27 bool is_main_frame, 28 content::RenderViewHost* render_view_host) { 29 if (!is_main_frame) return; 30 validated_url_ = validated_url; 31 Send(new ChromeViewMsg_RetrieveMetaTagContent(routing_id(), 32 validated_url, 33 meta_tag_)); 34 } 35 36 bool MetaTagObserver::OnMessageReceived(const IPC::Message& message) { 37 bool handled = true; 38 IPC_BEGIN_MESSAGE_MAP(MetaTagObserver, message) 39 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_DidRetrieveMetaTagContent, 40 OnDidRetrieveMetaTagContent) 41 IPC_MESSAGE_UNHANDLED(handled = false) 42 IPC_END_MESSAGE_MAP() 43 return handled; 44 } 45 46 void MetaTagObserver::OnDidRetrieveMetaTagContent( 47 bool success, 48 const std::string& tag_name, 49 const std::string& tag_content, 50 const GURL& expected_url) { 51 if (!success || tag_name != meta_tag_ || validated_url_ != expected_url || 52 tag_content.size() >= chrome::kMaxMetaTagAttributeLength) { 53 return; 54 } 55 HandleMetaTagContent(tag_content, expected_url); 56 } 57