Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(251)

Side by Side Diff: chrome/browser/ui/search_engines/search_engine_tab_helper.cc

Issue 2746293005: Migrated ChromeViewHostMsg_PageHasOSDD to Mojo. (Closed)
Patch Set: Removed public constructor and re-added mojo file. Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « chrome/browser/ui/search_engines/search_engine_tab_helper.h ('k') | chrome/common/BUILD.gn » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/ui/search_engines/search_engine_tab_helper.h" 5 #include "chrome/browser/ui/search_engines/search_engine_tab_helper.h"
6 6
7 #include "base/memory/ptr_util.h" 7 #include "base/memory/ptr_util.h"
8 #include "base/metrics/histogram_macros.h" 8 #include "base/metrics/histogram_macros.h"
9 #include "chrome/browser/profiles/profile.h" 9 #include "chrome/browser/profiles/profile.h"
10 #include "chrome/browser/search_engines/template_url_fetcher_factory.h" 10 #include "chrome/browser/search_engines/template_url_fetcher_factory.h"
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
65 (url.path().length() > 1)) { 65 (url.path().length() > 1)) {
66 return base::string16(); 66 return base::string16();
67 } 67 }
68 68
69 return TemplateURL::GenerateKeyword(url); 69 return TemplateURL::GenerateKeyword(url);
70 } 70 }
71 71
72 void AssociateURLFetcherWithWebContents(content::WebContents* web_contents, 72 void AssociateURLFetcherWithWebContents(content::WebContents* web_contents,
73 net::URLFetcher* url_fetcher) { 73 net::URLFetcher* url_fetcher) {
74 content::AssociateURLFetcherWithRenderFrame( 74 content::AssociateURLFetcherWithRenderFrame(
75 url_fetcher, 75 url_fetcher, url::Origin(web_contents->GetURL()),
76 url::Origin(web_contents->GetURL()),
77 web_contents->GetRenderProcessHost()->GetID(), 76 web_contents->GetRenderProcessHost()->GetID(),
78 web_contents->GetMainFrame()->GetRoutingID()); 77 web_contents->GetMainFrame()->GetRoutingID());
79 } 78 }
80 79
81 } // namespace 80 } // namespace
82 81
83 SearchEngineTabHelper::~SearchEngineTabHelper() { 82 SearchEngineTabHelper::~SearchEngineTabHelper() {
84 } 83 }
85 84
86 void SearchEngineTabHelper::DidFinishNavigation( 85 void SearchEngineTabHelper::DidFinishNavigation(
87 content::NavigationHandle* handle) { 86 content::NavigationHandle* handle) {
88 GenerateKeywordIfNecessary(handle); 87 GenerateKeywordIfNecessary(handle);
89 } 88 }
90 89
91 bool SearchEngineTabHelper::OnMessageReceived(const IPC::Message& message) {
92 bool handled = true;
93 IPC_BEGIN_MESSAGE_MAP(SearchEngineTabHelper, message)
94 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_PageHasOSDD, OnPageHasOSDD)
95 IPC_MESSAGE_UNHANDLED(handled = false)
96 IPC_END_MESSAGE_MAP()
97
98 return handled;
99 }
100
101 bool SearchEngineTabHelper::OnMessageReceived(
102 const IPC::Message& message,
103 content::RenderFrameHost* render_frame_host) {
104 return OnMessageReceived(message);
105 }
106
107 SearchEngineTabHelper::SearchEngineTabHelper(WebContents* web_contents) 90 SearchEngineTabHelper::SearchEngineTabHelper(WebContents* web_contents)
108 : content::WebContentsObserver(web_contents) { 91 : content::WebContentsObserver(web_contents),
92 osdd_handler_bindings_(web_contents, this) {
109 DCHECK(web_contents); 93 DCHECK(web_contents);
110 } 94 }
111 95
112 void SearchEngineTabHelper::OnPageHasOSDD( 96 void SearchEngineTabHelper::PageHasOpenSearchDescriptionDocument(
113 const GURL& page_url, 97 const GURL& page_url,
114 const GURL& osdd_url) { 98 const GURL& osdd_url) {
115 // Checks to see if we should generate a keyword based on the OSDD, and if 99 // Checks to see if we should generate a keyword based on the OSDD, and if
116 // necessary uses TemplateURLFetcher to download the OSDD and create a 100 // necessary uses TemplateURLFetcher to download the OSDD and create a
117 // keyword. 101 // keyword.
118 102
103 // Only accept messages from the main frame.
104 if (osdd_handler_bindings_.GetCurrentTargetFrame() !=
105 web_contents()->GetMainFrame())
dcheng 2017/03/16 05:57:43 Huh. Did we not check this in the past? I guess th
106 return;
107
119 // Make sure that the page is the current page and other basic checks. 108 // Make sure that the page is the current page and other basic checks.
120 // When |page_url| has file: scheme, this method doesn't work because of 109 // When |page_url| has file: scheme, this method doesn't work because of
121 // http://b/issue?id=863583. For that reason, this doesn't check and allow 110 // http://b/issue?id=863583. For that reason, this doesn't check and allow
122 // urls referring to osdd urls with same schemes. 111 // urls referring to osdd urls with same schemes.
123 if (!osdd_url.is_valid() || !osdd_url.SchemeIsHTTPOrHTTPS()) 112 if (!osdd_url.is_valid() || !osdd_url.SchemeIsHTTPOrHTTPS())
124 return; 113 return;
125 114
126 Profile* profile = 115 Profile* profile =
127 Profile::FromBrowserContext(web_contents()->GetBrowserContext()); 116 Profile::FromBrowserContext(web_contents()->GetBrowserContext());
128 if (page_url != web_contents()->GetLastCommittedURL() || 117 if (page_url != web_contents()->GetLastCommittedURL() ||
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
217 if (current_favicon.is_valid()) { 206 if (current_favicon.is_valid()) {
218 data.favicon_url = current_favicon; 207 data.favicon_url = current_favicon;
219 } else if (handle->GetReferrer().url.is_valid()) { 208 } else if (handle->GetReferrer().url.is_valid()) {
220 data.favicon_url = 209 data.favicon_url =
221 TemplateURL::GenerateFaviconURL(handle->GetReferrer().url); 210 TemplateURL::GenerateFaviconURL(handle->GetReferrer().url);
222 } 211 }
223 data.safe_for_autoreplace = true; 212 data.safe_for_autoreplace = true;
224 data.input_encodings.push_back(handle->GetSearchableFormEncoding()); 213 data.input_encodings.push_back(handle->GetSearchableFormEncoding());
225 url_service->Add(base::MakeUnique<TemplateURL>(data)); 214 url_service->Add(base::MakeUnique<TemplateURL>(data));
226 } 215 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/search_engines/search_engine_tab_helper.h ('k') | chrome/common/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698