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

Side by Side Diff: chrome/renderer/chrome_render_frame_observer.cc

Issue 2393513004: Convert app banners to use Mojo. (Closed)
Patch Set: Rebase Created 4 years, 2 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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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/renderer/chrome_render_frame_observer.h" 5 #include "chrome/renderer/chrome_render_frame_observer.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <string.h> 8 #include <string.h>
9 9
10 #include <limits> 10 #include <limits>
11 #include <string> 11 #include <string>
12 #include <utility>
12 #include <vector> 13 #include <vector>
13 14
14 #include "base/command_line.h" 15 #include "base/command_line.h"
15 #include "base/metrics/histogram.h" 16 #include "base/metrics/histogram.h"
16 #include "base/strings/string_number_conversions.h" 17 #include "base/strings/string_number_conversions.h"
17 #include "base/strings/utf_string_conversions.h" 18 #include "base/strings/utf_string_conversions.h"
18 #include "build/build_config.h" 19 #include "build/build_config.h"
19 #include "chrome/common/chrome_isolated_world_ids.h" 20 #include "chrome/common/chrome_isolated_world_ids.h"
20 #include "chrome/common/chrome_switches.h" 21 #include "chrome/common/chrome_switches.h"
21 #include "chrome/common/crash_keys.h" 22 #include "chrome/common/crash_keys.h"
22 #include "chrome/common/prerender_messages.h" 23 #include "chrome/common/prerender_messages.h"
23 #include "chrome/common/render_messages.h" 24 #include "chrome/common/render_messages.h"
24 #include "chrome/renderer/prerender/prerender_helper.h" 25 #include "chrome/renderer/prerender/prerender_helper.h"
25 #include "chrome/renderer/safe_browsing/phishing_classifier_delegate.h" 26 #include "chrome/renderer/safe_browsing/phishing_classifier_delegate.h"
26 #include "components/translate/content/renderer/translate_helper.h" 27 #include "components/translate/content/renderer/translate_helper.h"
27 #include "content/public/renderer/render_frame.h" 28 #include "content/public/renderer/render_frame.h"
28 #include "content/public/renderer/render_view.h" 29 #include "content/public/renderer/render_view.h"
29 #include "extensions/common/constants.h" 30 #include "extensions/common/constants.h"
30 #include "skia/ext/image_operations.h" 31 #include "skia/ext/image_operations.h"
31 #include "third_party/WebKit/public/platform/WebImage.h" 32 #include "third_party/WebKit/public/platform/WebImage.h"
32 #include "third_party/WebKit/public/platform/WebURLRequest.h" 33 #include "third_party/WebKit/public/platform/WebURLRequest.h"
33 #include "third_party/WebKit/public/platform/modules/app_banner/WebAppBannerProm ptReply.h"
34 #include "third_party/WebKit/public/web/WebDataSource.h" 34 #include "third_party/WebKit/public/web/WebDataSource.h"
35 #include "third_party/WebKit/public/web/WebDocument.h" 35 #include "third_party/WebKit/public/web/WebDocument.h"
36 #include "third_party/WebKit/public/web/WebElement.h" 36 #include "third_party/WebKit/public/web/WebElement.h"
37 #include "third_party/WebKit/public/web/WebFrameContentDumper.h" 37 #include "third_party/WebKit/public/web/WebFrameContentDumper.h"
38 #include "third_party/WebKit/public/web/WebLocalFrame.h" 38 #include "third_party/WebKit/public/web/WebLocalFrame.h"
39 #include "third_party/WebKit/public/web/WebNode.h" 39 #include "third_party/WebKit/public/web/WebNode.h"
40 #include "third_party/WebKit/public/web/WebSecurityPolicy.h" 40 #include "third_party/WebKit/public/web/WebSecurityPolicy.h"
41 #include "third_party/skia/include/core/SkBitmap.h" 41 #include "third_party/skia/include/core/SkBitmap.h"
42 #include "ui/gfx/codec/jpeg_codec.h" 42 #include "ui/gfx/codec/jpeg_codec.h"
43 #include "ui/gfx/geometry/size_f.h" 43 #include "ui/gfx/geometry/size_f.h"
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
100 } 100 }
101 101
102 return skia::ImageOperations::Resize(image.getSkBitmap(), 102 return skia::ImageOperations::Resize(image.getSkBitmap(),
103 skia::ImageOperations::RESIZE_GOOD, 103 skia::ImageOperations::RESIZE_GOOD,
104 static_cast<int>(scaled_size.width()), 104 static_cast<int>(scaled_size.width()),
105 static_cast<int>(scaled_size.height())); 105 static_cast<int>(scaled_size.height()));
106 } 106 }
107 107
108 } // namespace 108 } // namespace
109 109
110 // static
111 void ChromeRenderFrameObserver::BindBannerClient(
112 ChromeRenderFrameObserver* observer,
113 mojo::InterfaceRequest<blink::mojom::AppBannerClient> request) {
114 observer->banner_binding_.reset(
dcheng 2016/10/07 07:03:16 Nit: I think this can be replaced with Binding::Cl
dominickn 2016/10/13 00:18:15 Done.
115 new mojo::Binding<blink::mojom::AppBannerClient>(observer,
116 std::move(request)));
117 }
118
110 ChromeRenderFrameObserver::ChromeRenderFrameObserver( 119 ChromeRenderFrameObserver::ChromeRenderFrameObserver(
111 content::RenderFrame* render_frame) 120 content::RenderFrame* render_frame)
112 : content::RenderFrameObserver(render_frame), 121 : content::RenderFrameObserver(render_frame),
113 translate_helper_(nullptr), 122 translate_helper_(nullptr),
114 phishing_classifier_(nullptr) { 123 phishing_classifier_(nullptr) {
115 // Don't do anything for subframes. 124 // Don't do anything for subframes.
116 if (!render_frame->IsMainFrame()) 125 if (!render_frame->IsMainFrame())
117 return; 126 return;
118 127
119 const base::CommandLine& command_line = 128 const base::CommandLine& command_line =
(...skipping 22 matching lines...) Expand all
142 IPC_MESSAGE_HANDLER(ChromeViewMsg_RequestReloadImageForContextNode, 151 IPC_MESSAGE_HANDLER(ChromeViewMsg_RequestReloadImageForContextNode,
143 OnRequestReloadImageForContextNode) 152 OnRequestReloadImageForContextNode)
144 IPC_MESSAGE_HANDLER(ChromeViewMsg_RequestThumbnailForContextNode, 153 IPC_MESSAGE_HANDLER(ChromeViewMsg_RequestThumbnailForContextNode,
145 OnRequestThumbnailForContextNode) 154 OnRequestThumbnailForContextNode)
146 IPC_MESSAGE_HANDLER(ChromeViewMsg_SetClientSidePhishingDetection, 155 IPC_MESSAGE_HANDLER(ChromeViewMsg_SetClientSidePhishingDetection,
147 OnSetClientSidePhishingDetection) 156 OnSetClientSidePhishingDetection)
148 #if defined(ENABLE_PRINTING) 157 #if defined(ENABLE_PRINTING)
149 IPC_MESSAGE_HANDLER(PrintMsg_PrintNodeUnderContextMenu, 158 IPC_MESSAGE_HANDLER(PrintMsg_PrintNodeUnderContextMenu,
150 OnPrintNodeUnderContextMenu) 159 OnPrintNodeUnderContextMenu)
151 #endif 160 #endif
152 IPC_MESSAGE_HANDLER(ChromeViewMsg_AppBannerPromptRequest,
153 OnAppBannerPromptRequest)
154 IPC_MESSAGE_UNHANDLED(handled = false) 161 IPC_MESSAGE_UNHANDLED(handled = false)
155 IPC_END_MESSAGE_MAP() 162 IPC_END_MESSAGE_MAP()
156 163
157 return handled; 164 return handled;
158 } 165 }
159 166
160 void ChromeRenderFrameObserver::OnSetIsPrerendering( 167 void ChromeRenderFrameObserver::OnSetIsPrerendering(
161 prerender::PrerenderMode mode) { 168 prerender::PrerenderMode mode) {
162 if (mode != prerender::NO_PRERENDER) { 169 if (mode != prerender::NO_PRERENDER) {
163 // If the PrerenderHelper for this frame already exists, don't create it. It 170 // If the PrerenderHelper for this frame already exists, don't create it. It
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
233 bool enable_phishing_detection) { 240 bool enable_phishing_detection) {
234 #if defined(SAFE_BROWSING_CSD) 241 #if defined(SAFE_BROWSING_CSD)
235 phishing_classifier_ = 242 phishing_classifier_ =
236 enable_phishing_detection 243 enable_phishing_detection
237 ? safe_browsing::PhishingClassifierDelegate::Create(render_frame(), 244 ? safe_browsing::PhishingClassifierDelegate::Create(render_frame(),
238 nullptr) 245 nullptr)
239 : nullptr; 246 : nullptr;
240 #endif 247 #endif
241 } 248 }
242 249
243 void ChromeRenderFrameObserver::OnAppBannerPromptRequest( 250 void ChromeRenderFrameObserver::BannerPromptRequest(
244 int request_id, 251 blink::mojom::AppBannerServicePtr banner_service,
245 const std::string& platform) { 252 blink::mojom::AppBannerEventRequest event_request,
246 // App banner prompt requests are handled in the general chrome render frame 253 const std::string& platform,
247 // observer, not the AppBannerClient, as the AppBannerClient is created lazily 254 const BannerPromptRequestCallback& callback) {
248 // by blink and may not exist when the request is sent. 255 // Break up the InterfacePtr and InterfaceRequest so they can be passed
249 blink::WebAppBannerPromptReply reply = blink::WebAppBannerPromptReply::None; 256 // through to Blink as ScopedMessagePipeHandle. They will be reconstituted on
257 // the other side.
dcheng 2016/10/07 07:03:16 Maybe put a TODO here that we should be able to ge
258 mojo::ScopedMessagePipeHandle service_handle =
259 banner_service.PassInterface().PassHandle();
260 mojo::ScopedMessagePipeHandle event_handle = event_request.PassMessagePipe();
261
262 blink::mojom::AppBannerPromptReply reply =
263 blink::mojom::AppBannerPromptReply::NONE;
250 blink::WebString web_platform(base::UTF8ToUTF16(platform)); 264 blink::WebString web_platform(base::UTF8ToUTF16(platform));
251 blink::WebVector<blink::WebString> web_platforms(&web_platform, 1); 265 blink::WebVector<blink::WebString> web_platforms(&web_platform, 1);
252 266
253 blink::WebLocalFrame* frame = render_frame()->GetWebFrame(); 267 blink::WebLocalFrame* frame = render_frame()->GetWebFrame();
254 frame->willShowInstallBannerPrompt(request_id, web_platforms, &reply); 268 frame->willShowInstallBannerPrompt(std::move(service_handle),
269 std::move(event_handle), web_platforms,
270 &reply);
255 271
256 // Extract the referrer header for this site according to its referrer policy. 272 // Extract the referrer header for this site according to its referrer policy.
257 // Pass in an empty URL as the destination so that it is always treated 273 // Pass in an empty URL as the destination so that it is always treated
258 // as a cross-origin request. 274 // as a cross-origin request.
259 std::string referrer = blink::WebSecurityPolicy::generateReferrerHeader( 275 std::string referrer = blink::WebSecurityPolicy::generateReferrerHeader(
260 frame->document().referrerPolicy(), GURL(), 276 frame->document().referrerPolicy(), GURL(),
261 frame->document().outgoingReferrer()).utf8(); 277 frame->document().outgoingReferrer()).utf8();
262 278
263 Send(new ChromeViewHostMsg_AppBannerPromptReply( 279 callback.Run(reply, referrer);
264 routing_id(), request_id, reply, referrer));
265 } 280 }
266 281
267 void ChromeRenderFrameObserver::DidFinishLoad() { 282 void ChromeRenderFrameObserver::DidFinishLoad() {
268 WebLocalFrame* frame = render_frame()->GetWebFrame(); 283 WebLocalFrame* frame = render_frame()->GetWebFrame();
269 // Don't do anything for subframes. 284 // Don't do anything for subframes.
270 if (frame->parent()) 285 if (frame->parent())
271 return; 286 return;
272 287
273 GURL osdd_url = frame->document().openSearchDescriptionURL(); 288 GURL osdd_url = frame->document().openSearchDescriptionURL();
274 if (!osdd_url.is_empty()) { 289 if (!osdd_url.is_empty()) {
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
364 CapturePageText(FINAL_CAPTURE); 379 CapturePageText(FINAL_CAPTURE);
365 break; 380 break;
366 default: 381 default:
367 break; 382 break;
368 } 383 }
369 } 384 }
370 385
371 void ChromeRenderFrameObserver::OnDestruct() { 386 void ChromeRenderFrameObserver::OnDestruct() {
372 delete this; 387 delete this;
373 } 388 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698