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

Side by Side Diff: chrome/browser/ui/tab_contents/core_tab_helper.cc

Issue 2737893002: Mojoify the RequestThumbnailForContextNode IPC message and reply (Closed)
Patch Set: 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/tab_contents/core_tab_helper.h" 5 #include "chrome/browser/ui/tab_contents/core_tab_helper.h"
6 6
7 #include <string> 7 #include <string>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
11 #include "base/command_line.h" 11 #include "base/command_line.h"
12 #include "base/memory/ptr_util.h" 12 #include "base/memory/ptr_util.h"
13 #include "base/metrics/histogram_macros.h" 13 #include "base/metrics/histogram_macros.h"
14 #include "base/profiler/scoped_tracker.h" 14 #include "base/profiler/scoped_tracker.h"
15 #include "base/strings/stringprintf.h" 15 #include "base/strings/stringprintf.h"
16 #include "build/build_config.h" 16 #include "build/build_config.h"
17 #include "chrome/browser/profiles/profile.h" 17 #include "chrome/browser/profiles/profile.h"
18 #include "chrome/browser/search_engines/template_url_service_factory.h" 18 #include "chrome/browser/search_engines/template_url_service_factory.h"
19 #include "chrome/browser/ui/browser_command_controller.h" 19 #include "chrome/browser/ui/browser_command_controller.h"
20 #include "chrome/browser/ui/browser_finder.h" 20 #include "chrome/browser/ui/browser_finder.h"
21 #include "chrome/common/chrome_switches.h" 21 #include "chrome/common/chrome_switches.h"
22 #include "chrome/common/render_messages.h" 22 #include "chrome/common/render_messages.h"
23 #include "chrome/common/thumbnail_capturer.mojom.h"
23 #include "chrome/grit/generated_resources.h" 24 #include "chrome/grit/generated_resources.h"
24 #include "components/guest_view/browser/guest_view_manager.h" 25 #include "components/guest_view/browser/guest_view_manager.h"
25 #include "components/search_engines/template_url.h" 26 #include "components/search_engines/template_url.h"
26 #include "components/search_engines/template_url_service.h" 27 #include "components/search_engines/template_url_service.h"
27 #include "components/strings/grit/components_strings.h" 28 #include "components/strings/grit/components_strings.h"
28 #include "components/web_cache/browser/web_cache_manager.h" 29 #include "components/web_cache/browser/web_cache_manager.h"
29 #include "content/public/browser/navigation_controller.h" 30 #include "content/public/browser/navigation_controller.h"
30 #include "content/public/browser/navigation_entry.h" 31 #include "content/public/browser/navigation_entry.h"
31 #include "content/public/browser/render_frame_host.h" 32 #include "content/public/browser/render_frame_host.h"
32 #include "content/public/browser/render_process_host.h" 33 #include "content/public/browser/render_process_host.h"
33 #include "content/public/browser/render_view_host.h" 34 #include "content/public/browser/render_view_host.h"
34 #include "content/public/browser/web_contents.h" 35 #include "content/public/browser/web_contents.h"
35 #include "content/public/common/content_switches.h" 36 #include "content/public/common/content_switches.h"
36 #include "content/public/common/context_menu_params.h" 37 #include "content/public/common/context_menu_params.h"
37 #include "net/base/load_states.h" 38 #include "net/base/load_states.h"
38 #include "net/http/http_request_headers.h" 39 #include "net/http/http_request_headers.h"
40 #include "services/service_manager/public/cpp/interface_provider.h"
39 #include "ui/base/l10n/l10n_util.h" 41 #include "ui/base/l10n/l10n_util.h"
40 42
41 #if !defined(OS_ANDROID) 43 #if !defined(OS_ANDROID)
42 #include "chrome/browser/ui/browser.h" 44 #include "chrome/browser/ui/browser.h"
43 #endif 45 #endif
44 46
45 using content::WebContents; 47 using content::WebContents;
46 48
47 namespace { 49 namespace {
48 50
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
98 #if !defined(OS_ANDROID) 100 #if !defined(OS_ANDROID)
99 Browser* browser = chrome::FindBrowserWithWebContents(web_contents()); 101 Browser* browser = chrome::FindBrowserWithWebContents(web_contents());
100 if (!browser) 102 if (!browser)
101 return; 103 return;
102 104
103 browser->command_controller()->ContentRestrictionsChanged(); 105 browser->command_controller()->ContentRestrictionsChanged();
104 #endif 106 #endif
105 } 107 }
106 108
107 void CoreTabHelper::SearchByImageInNewTab( 109 void CoreTabHelper::SearchByImageInNewTab(
108 content::RenderFrameHost* render_frame_host, const GURL& src_url) { 110 content::RenderFrameHost* render_frame_host,
111 const GURL& src_url) {
109 RequestThumbnailForContextNode( 112 RequestThumbnailForContextNode(
110 render_frame_host, 113 render_frame_host, kImageSearchThumbnailMinSize,
111 kImageSearchThumbnailMinSize, 114 gfx::Size(kImageSearchThumbnailMaxWidth, kImageSearchThumbnailMaxHeight),
112 gfx::Size(kImageSearchThumbnailMaxWidth,
113 kImageSearchThumbnailMaxHeight),
114 base::Bind(&CoreTabHelper::DoSearchByImageInNewTab, 115 base::Bind(&CoreTabHelper::DoSearchByImageInNewTab,
115 base::Unretained(this), 116 base::Unretained(this), src_url));
116 src_url));
117 } 117 }
118 118
119 void CoreTabHelper::RequestThumbnailForContextNode( 119 void CoreTabHelper::RequestThumbnailForContextNode(
120 content::RenderFrameHost* render_frame_host, 120 content::RenderFrameHost* render_frame_host,
121 int minimum_size, 121 int thumbnail_min_area_pixels,
122 gfx::Size maximum_size, 122 gfx::Size thumbnail_max_size_pixels,
123 const ContextNodeThumbnailCallback& callback) { 123 const ContextNodeThumbnailCallback& callback) {
124 int callback_id = thumbnail_callbacks_.Add( 124 chrome::mojom::ThumbnailCapturerPtr* thumbnail_capturer =
125 base::MakeUnique<ContextNodeThumbnailCallback>(callback)); 125 new chrome::mojom::ThumbnailCapturerPtr();
126 int interface_id =
127 thumbnail_capturers_.Add(base::WrapUnique(thumbnail_capturer));
watk 2017/03/08 03:48:51 WDYT about this? I don't like that it can leak Int
tibell 2017/03/08 04:19:49 As discussed offline. Lets try the weak ptr approa
128 render_frame_host->GetRemoteInterfaces()->GetInterface(thumbnail_capturer);
129 (*thumbnail_capturer)
130 ->RequestThumbnailForContextNode(
131 thumbnail_min_area_pixels, thumbnail_max_size_pixels,
132 base::Bind(&CoreTabHelper::OnThumbnailForContextNodeReceived,
133 base::Unretained(this), interface_id, callback));
134 }
126 135
127 render_frame_host->Send( 136 void CoreTabHelper::OnThumbnailForContextNodeReceived(
128 new ChromeViewMsg_RequestThumbnailForContextNode( 137 int interface_id,
129 render_frame_host->GetRoutingID(), 138 const ContextNodeThumbnailCallback& callback,
130 minimum_size, 139 const std::string& thumbnail_data,
131 maximum_size, 140 const gfx::Size& original_size) {
132 callback_id)); 141 thumbnail_capturers_.Remove(interface_id);
142 callback.Run(thumbnail_data, original_size);
133 } 143 }
134 144
135 // static 145 // static
136 bool CoreTabHelper::GetStatusTextForWebContents( 146 bool CoreTabHelper::GetStatusTextForWebContents(
137 base::string16* status_text, content::WebContents* source) { 147 base::string16* status_text, content::WebContents* source) {
138 // TODO(robliao): Remove ScopedTracker below once https://crbug.com/467185 is 148 // TODO(robliao): Remove ScopedTracker below once https://crbug.com/467185 is
139 // fixed. 149 // fixed.
140 tracked_objects::ScopedTracker tracking_profile1( 150 tracked_objects::ScopedTracker tracking_profile1(
141 FROM_HERE_WITH_EXPLICIT_FUNCTION( 151 FROM_HERE_WITH_EXPLICIT_FUNCTION(
142 "467185 CoreTabHelper::GetStatusTextForWebContents1")); 152 "467185 CoreTabHelper::GetStatusTextForWebContents1"));
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after
294 } 304 }
295 305
296 void CoreTabHelper::BeforeUnloadFired(const base::TimeTicks& proceed_time) { 306 void CoreTabHelper::BeforeUnloadFired(const base::TimeTicks& proceed_time) {
297 before_unload_end_time_ = proceed_time; 307 before_unload_end_time_ = proceed_time;
298 } 308 }
299 309
300 void CoreTabHelper::BeforeUnloadDialogCancelled() { 310 void CoreTabHelper::BeforeUnloadDialogCancelled() {
301 OnCloseCanceled(); 311 OnCloseCanceled();
302 } 312 }
303 313
304 bool CoreTabHelper::OnMessageReceived(
305 const IPC::Message& message,
306 content::RenderFrameHost* render_frame_host) {
307 bool handled = true;
308 IPC_BEGIN_MESSAGE_MAP(CoreTabHelper, message)
309 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_RequestThumbnailForContextNode_ACK,
310 OnRequestThumbnailForContextNodeACK)
311 IPC_MESSAGE_UNHANDLED(handled = false)
312 IPC_END_MESSAGE_MAP()
313 return handled;
314 }
315
316 void CoreTabHelper::OnRequestThumbnailForContextNodeACK(
317 const std::string& thumbnail_data,
318 const gfx::Size& original_size,
319 int callback_id) {
320 ContextNodeThumbnailCallback* callback =
321 thumbnail_callbacks_.Lookup(callback_id);
322 if (!callback)
323 return;
324 callback->Run(thumbnail_data, original_size);
325 thumbnail_callbacks_.Remove(callback_id);
326 }
327
328 // Handles the image thumbnail for the context node, composes a image search 314 // Handles the image thumbnail for the context node, composes a image search
329 // request based on the received thumbnail and opens the request in a new tab. 315 // request based on the received thumbnail and opens the request in a new tab.
330 void CoreTabHelper::DoSearchByImageInNewTab(const GURL& src_url, 316 void CoreTabHelper::DoSearchByImageInNewTab(const GURL& src_url,
331 const std::string& thumbnail_data, 317 const std::string& thumbnail_data,
332 const gfx::Size& original_size) { 318 const gfx::Size& original_size) {
333 if (thumbnail_data.empty()) 319 if (thumbnail_data.empty())
334 return; 320 return;
335 321
336 Profile* profile = 322 Profile* profile =
337 Profile::FromBrowserContext(web_contents()->GetBrowserContext()); 323 Profile::FromBrowserContext(web_contents()->GetBrowserContext());
(...skipping 27 matching lines...) Expand all
365 DCHECK(!content_type.empty()); 351 DCHECK(!content_type.empty());
366 open_url_params.uses_post = true; 352 open_url_params.uses_post = true;
367 open_url_params.post_data = content::ResourceRequestBody::CreateFromBytes( 353 open_url_params.post_data = content::ResourceRequestBody::CreateFromBytes(
368 post_data.data(), post_data.size()); 354 post_data.data(), post_data.size());
369 open_url_params.extra_headers += base::StringPrintf( 355 open_url_params.extra_headers += base::StringPrintf(
370 "%s: %s\r\n", net::HttpRequestHeaders::kContentType, 356 "%s: %s\r\n", net::HttpRequestHeaders::kContentType,
371 content_type.c_str()); 357 content_type.c_str());
372 } 358 }
373 web_contents()->OpenURL(open_url_params); 359 web_contents()->OpenURL(open_url_params);
374 } 360 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698