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.
5 #include "chrome/browser/android/meta_tag_observer.h"
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"
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.";
21 MetaTagObserver::~MetaTagObserver() {
24 void MetaTagObserver::DidFinishLoad(
26 const GURL& validated_url,
28 content::RenderViewHost* render_view_host) {
29 if (!is_main_frame) return;
30 validated_url_ = validated_url;
31 Send(new ChromeViewMsg_RetrieveMetaTagContent(routing_id(),
36 bool MetaTagObserver::OnMessageReceived(const IPC::Message& message) {
38 IPC_BEGIN_MESSAGE_MAP(MetaTagObserver, message)
39 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_DidRetrieveMetaTagContent,
40 OnDidRetrieveMetaTagContent)
41 IPC_MESSAGE_UNHANDLED(handled = false)
46 void MetaTagObserver::OnDidRetrieveMetaTagContent(
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) {
55 HandleMetaTagContent(tag_content, expected_url);