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

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

Issue 2746293005: Migrated ChromeViewHostMsg_PageHasOSDD to Mojo. (Closed)
Patch Set: Manually reverted format changes (from my auto-formatting plugin). 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
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"
11 #include "chrome/browser/search_engines/template_url_service_factory.h" 11 #include "chrome/browser/search_engines/template_url_service_factory.h"
12 #include "chrome/browser/ui/search_engines/edit_search_engine_controller.h" 12 #include "chrome/browser/ui/search_engines/edit_search_engine_controller.h"
13 #include "chrome/common/render_messages.h" 13 #include "chrome/common/render_messages.h"
14 #include "chrome/common/url_constants.h" 14 #include "chrome/common/url_constants.h"
15 #include "components/search_engines/template_url.h" 15 #include "components/search_engines/template_url.h"
16 #include "components/search_engines/template_url_fetcher.h" 16 #include "components/search_engines/template_url_fetcher.h"
17 #include "components/search_engines/template_url_service.h" 17 #include "components/search_engines/template_url_service.h"
18 #include "content/public/browser/favicon_status.h" 18 #include "content/public/browser/favicon_status.h"
19 #include "content/public/browser/navigation_controller.h" 19 #include "content/public/browser/navigation_controller.h"
20 #include "content/public/browser/navigation_entry.h" 20 #include "content/public/browser/navigation_entry.h"
21 #include "content/public/browser/navigation_handle.h" 21 #include "content/public/browser/navigation_handle.h"
22 #include "content/public/browser/render_frame_host.h" 22 #include "content/public/browser/render_frame_host.h"
23 #include "content/public/browser/render_process_host.h" 23 #include "content/public/browser/render_process_host.h"
24 #include "content/public/browser/web_contents.h" 24 #include "content/public/browser/web_contents.h"
25 #include "content/public/common/url_fetcher.h" 25 #include "content/public/common/url_fetcher.h"
26 #include "services/service_manager/public/cpp/interface_registry.h"
26 27
27 using content::NavigationController; 28 using content::NavigationController;
28 using content::NavigationEntry; 29 using content::NavigationEntry;
29 using content::WebContents; 30 using content::WebContents;
30 31
31 DEFINE_WEB_CONTENTS_USER_DATA_KEY(SearchEngineTabHelper); 32 DEFINE_WEB_CONTENTS_USER_DATA_KEY(SearchEngineTabHelper);
32 33
33 namespace { 34 namespace {
34 35
35 // Returns true if the entry's transition type is FORM_SUBMIT. 36 // Returns true if the entry's transition type is FORM_SUBMIT.
(...skipping 29 matching lines...) Expand all
65 (url.path().length() > 1)) { 66 (url.path().length() > 1)) {
66 return base::string16(); 67 return base::string16();
67 } 68 }
68 69
69 return TemplateURL::GenerateKeyword(url); 70 return TemplateURL::GenerateKeyword(url);
70 } 71 }
71 72
72 void AssociateURLFetcherWithWebContents(content::WebContents* web_contents, 73 void AssociateURLFetcherWithWebContents(content::WebContents* web_contents,
73 net::URLFetcher* url_fetcher) { 74 net::URLFetcher* url_fetcher) {
74 content::AssociateURLFetcherWithRenderFrame( 75 content::AssociateURLFetcherWithRenderFrame(
75 url_fetcher, 76 url_fetcher, url::Origin(web_contents->GetURL()),
76 url::Origin(web_contents->GetURL()),
77 web_contents->GetRenderProcessHost()->GetID(), 77 web_contents->GetRenderProcessHost()->GetID(),
78 web_contents->GetMainFrame()->GetRoutingID()); 78 web_contents->GetMainFrame()->GetRoutingID());
79 } 79 }
80 80
81 } // namespace 81 } // namespace
82 82
83 SearchEngineTabHelper::SearchEngineTabHelper()
84 : osdd_handler_binding_(this), weak_factory_(this) {
85 }
86
83 SearchEngineTabHelper::~SearchEngineTabHelper() { 87 SearchEngineTabHelper::~SearchEngineTabHelper() {
84 } 88 }
85 89
90 void SearchEngineTabHelper::RenderFrameCreated(
91 content::RenderFrameHost* render_frame_host) {
92 render_frame_host->GetInterfaceRegistry()->AddInterface(
93 base::Bind(&SearchEngineTabHelper::OnOSDDHandlerRequest,
94 weak_factory_.GetWeakPtr()));
95 }
96
86 void SearchEngineTabHelper::DidFinishNavigation( 97 void SearchEngineTabHelper::DidFinishNavigation(
87 content::NavigationHandle* handle) { 98 content::NavigationHandle* handle) {
88 GenerateKeywordIfNecessary(handle); 99 GenerateKeywordIfNecessary(handle);
89 } 100 }
90 101
91 bool SearchEngineTabHelper::OnMessageReceived(const IPC::Message& message) { 102 SearchEngineTabHelper::SearchEngineTabHelper(WebContents* web_contents)
92 bool handled = true; 103 : content::WebContentsObserver(web_contents),
93 IPC_BEGIN_MESSAGE_MAP(SearchEngineTabHelper, message) 104 osdd_handler_binding_(this),
94 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_PageHasOSDD, OnPageHasOSDD) 105 weak_factory_(this) {
95 IPC_MESSAGE_UNHANDLED(handled = false) 106 DCHECK(web_contents);
96 IPC_END_MESSAGE_MAP()
97
98 return handled;
99 } 107 }
100 108
101 bool SearchEngineTabHelper::OnMessageReceived( 109 void SearchEngineTabHelper::OnOSDDHandlerRequest(
102 const IPC::Message& message, 110 chrome::mojom::OSDDHandlerRequest request) {
103 content::RenderFrameHost* render_frame_host) { 111 if (!osdd_handler_binding_.is_bound()) {
104 return OnMessageReceived(message); 112 osdd_handler_binding_.Bind(std::move(request));
105 } 113 }
106
107 SearchEngineTabHelper::SearchEngineTabHelper(WebContents* web_contents)
108 : content::WebContentsObserver(web_contents) {
109 DCHECK(web_contents);
110 } 114 }
111 115
112 void SearchEngineTabHelper::OnPageHasOSDD( 116 void SearchEngineTabHelper::OnPageHasOSDD(
113 const GURL& page_url, 117 const GURL& page_url,
114 const GURL& osdd_url) { 118 const GURL& osdd_url) {
115 // Checks to see if we should generate a keyword based on the OSDD, and if 119 // 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 120 // necessary uses TemplateURLFetcher to download the OSDD and create a
117 // keyword. 121 // keyword.
118 122
119 // Make sure that the page is the current page and other basic checks. 123 // Make sure that the page is the current page and other basic checks.
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
217 if (current_favicon.is_valid()) { 221 if (current_favicon.is_valid()) {
218 data.favicon_url = current_favicon; 222 data.favicon_url = current_favicon;
219 } else if (handle->GetReferrer().url.is_valid()) { 223 } else if (handle->GetReferrer().url.is_valid()) {
220 data.favicon_url = 224 data.favicon_url =
221 TemplateURL::GenerateFaviconURL(handle->GetReferrer().url); 225 TemplateURL::GenerateFaviconURL(handle->GetReferrer().url);
222 } 226 }
223 data.safe_for_autoreplace = true; 227 data.safe_for_autoreplace = true;
224 data.input_encodings.push_back(handle->GetSearchableFormEncoding()); 228 data.input_encodings.push_back(handle->GetSearchableFormEncoding());
225 url_service->Add(base::MakeUnique<TemplateURL>(data)); 229 url_service->Add(base::MakeUnique<TemplateURL>(data));
226 } 230 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698