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

Side by Side Diff: content/browser/browser_plugin/browser_plugin_guest.cc

Issue 11028019: Browser plugin: Implement loadRedirect event. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Initial patch Created 8 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 | Annotate | Revision Log
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 "content/browser/browser_plugin/browser_plugin_guest.h" 5 #include "content/browser/browser_plugin/browser_plugin_guest.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "content/browser/browser_plugin/browser_plugin_guest_helper.h" 9 #include "content/browser/browser_plugin/browser_plugin_guest_helper.h"
10 #include "content/browser/browser_plugin/browser_plugin_host_factory.h" 10 #include "content/browser/browser_plugin/browser_plugin_host_factory.h"
11 #include "content/browser/renderer_host/render_view_host_impl.h" 11 #include "content/browser/renderer_host/render_view_host_impl.h"
12 #include "content/browser/renderer_host/render_widget_host_impl.h" 12 #include "content/browser/renderer_host/render_widget_host_impl.h"
13 #include "content/browser/web_contents/web_contents_impl.h" 13 #include "content/browser/web_contents/web_contents_impl.h"
14 #include "content/common/browser_plugin_messages.h" 14 #include "content/common/browser_plugin_messages.h"
15 #include "content/common/view_messages.h" 15 #include "content/common/view_messages.h"
16 #include "content/public/browser/notification_service.h"
17 #include "content/public/browser/notification_types.h"
16 #include "content/public/browser/render_process_host.h" 18 #include "content/public/browser/render_process_host.h"
17 #include "content/public/browser/render_widget_host_view.h" 19 #include "content/public/browser/render_widget_host_view.h"
20 #include "content/public/browser/resource_request_details.h"
18 #include "content/public/browser/user_metrics.h" 21 #include "content/public/browser/user_metrics.h"
19 #include "content/public/common/result_codes.h" 22 #include "content/public/common/result_codes.h"
20 #include "content/browser/browser_plugin/browser_plugin_host_factory.h" 23 #include "content/browser/browser_plugin/browser_plugin_host_factory.h"
21 #include "ui/surface/transport_dib.h" 24 #include "ui/surface/transport_dib.h"
25 #include "webkit/glue/resource_type.h"
22 26
23 namespace content { 27 namespace content {
24 28
25 // static 29 // static
26 BrowserPluginHostFactory* BrowserPluginGuest::factory_ = NULL; 30 BrowserPluginHostFactory* BrowserPluginGuest::factory_ = NULL;
27 31
28 namespace { 32 namespace {
29 const int kGuestHangTimeoutMs = 5000; 33 const int kGuestHangTimeoutMs = 5000;
30 } 34 }
31 35
32 BrowserPluginGuest::BrowserPluginGuest(int instance_id, 36 BrowserPluginGuest::BrowserPluginGuest(int instance_id,
33 WebContentsImpl* web_contents, 37 WebContentsImpl* web_contents,
34 RenderViewHost* render_view_host) 38 RenderViewHost* render_view_host)
35 : WebContentsObserver(web_contents), 39 : WebContentsObserver(web_contents),
36 embedder_render_process_host_(NULL), 40 embedder_render_process_host_(NULL),
37 instance_id_(instance_id), 41 instance_id_(instance_id),
38 #if defined(OS_WIN) 42 #if defined(OS_WIN)
39 damage_buffer_size_(0), 43 damage_buffer_size_(0),
40 #endif 44 #endif
41 pending_update_counter_(0), 45 pending_update_counter_(0),
42 guest_hang_timeout_( 46 guest_hang_timeout_(
43 base::TimeDelta::FromMilliseconds(kGuestHangTimeoutMs)) { 47 base::TimeDelta::FromMilliseconds(kGuestHangTimeoutMs)) {
44 DCHECK(web_contents); 48 DCHECK(web_contents);
45 // |render_view_host| manages the ownership of this BrowserPluginGuestHelper. 49 // |render_view_host| manages the ownership of this BrowserPluginGuestHelper.
46 new BrowserPluginGuestHelper(this, render_view_host); 50 new BrowserPluginGuestHelper(this, render_view_host);
51
52 notification_registrar_.Add(
53 this, content::NOTIFICATION_RESOURCE_RECEIVED_REDIRECT,
54 content::Source<content::WebContents>(web_contents));
47 } 55 }
48 56
49 BrowserPluginGuest::~BrowserPluginGuest() { 57 BrowserPluginGuest::~BrowserPluginGuest() {
50 } 58 }
51 59
52 // static 60 // static
53 BrowserPluginGuest* BrowserPluginGuest::Create( 61 BrowserPluginGuest* BrowserPluginGuest::Create(
54 int instance_id, 62 int instance_id,
55 WebContentsImpl* web_contents, 63 WebContentsImpl* web_contents,
56 content::RenderViewHost* render_view_host) { 64 content::RenderViewHost* render_view_host) {
57 RecordAction(UserMetricsAction("BrowserPlugin.Guest.Create")); 65 RecordAction(UserMetricsAction("BrowserPlugin.Guest.Create"));
58 if (factory_) { 66 if (factory_) {
59 return factory_->CreateBrowserPluginGuest(instance_id, 67 return factory_->CreateBrowserPluginGuest(instance_id,
60 web_contents, 68 web_contents,
61 render_view_host); 69 render_view_host);
62 } 70 }
63 return new BrowserPluginGuest(instance_id, web_contents, render_view_host); 71 return new BrowserPluginGuest(instance_id, web_contents, render_view_host);
64 } 72 }
65 73
74 void BrowserPluginGuest::Observe(int type,
75 const NotificationSource& source,
76 const NotificationDetails& details) {
77 switch (type) {
78 case NOTIFICATION_RESOURCE_RECEIVED_REDIRECT: {
79 DCHECK_EQ(Source<WebContents>(source).ptr(), web_contents());
80 ResourceRedirectDetails* resource_redirect_details =
81 Details<ResourceRedirectDetails>(details).ptr();
82 bool is_top_level =
83 resource_redirect_details->resource_type == ResourceType::MAIN_FRAME;
84 LoadRedirect(resource_redirect_details->url,
85 resource_redirect_details->new_url,
86 is_top_level);
87 break;
88 }
89 default:
90 NOTREACHED() << "Unexpected notification sent.";
91 break;
92 }
93 }
94
66 bool BrowserPluginGuest::ViewTakeFocus(bool reverse) { 95 bool BrowserPluginGuest::ViewTakeFocus(bool reverse) {
67 SendMessageToEmbedder( 96 SendMessageToEmbedder(
68 new BrowserPluginMsg_AdvanceFocus(instance_id(), reverse)); 97 new BrowserPluginMsg_AdvanceFocus(instance_id(), reverse));
69 return true; 98 return true;
70 } 99 }
71 100
72 void BrowserPluginGuest::Go(int relative_index) { 101 void BrowserPluginGuest::Go(int relative_index) {
73 web_contents()->GetController().GoToOffset(relative_index); 102 web_contents()->GetController().GoToOffset(relative_index);
74 } 103 }
75 104
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after
263 gfx::Rect screen_pos(initial_pos); 292 gfx::Rect screen_pos(initial_pos);
264 screen_pos.Offset(guest_rect_.origin()); 293 screen_pos.Offset(guest_rect_.origin());
265 static_cast<WebContentsImpl*>(web_contents())->ShowCreatedWidget(route_id, 294 static_cast<WebContentsImpl*>(web_contents())->ShowCreatedWidget(route_id,
266 screen_pos); 295 screen_pos);
267 } 296 }
268 297
269 void BrowserPluginGuest::SetCursor(const WebCursor& cursor) { 298 void BrowserPluginGuest::SetCursor(const WebCursor& cursor) {
270 cursor_ = cursor; 299 cursor_ = cursor;
271 } 300 }
272 301
302 void BrowserPluginGuest::LoadRedirect(
303 const GURL& old_url,
304 const GURL& new_url,
305 bool is_top_level) {
306 SendMessageToEmbedder(
307 new BrowserPluginMsg_LoadRedirect(
308 instance_id(), old_url, new_url, is_top_level));
309 }
310
273 void BrowserPluginGuest::DidCommitProvisionalLoadForFrame( 311 void BrowserPluginGuest::DidCommitProvisionalLoadForFrame(
274 int64 frame_id, 312 int64 frame_id,
275 bool is_main_frame, 313 bool is_main_frame,
276 const GURL& url, 314 const GURL& url,
277 PageTransition transition_type, 315 PageTransition transition_type,
278 RenderViewHost* render_view_host) { 316 RenderViewHost* render_view_host) {
279 // Inform its embedder of the updated URL. 317 // Inform its embedder of the updated URL.
280 if (is_main_frame) { 318 if (is_main_frame) {
281 SendMessageToEmbedder( 319 SendMessageToEmbedder(
282 new BrowserPluginMsg_DidNavigate( 320 new BrowserPluginMsg_DidNavigate(
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
316 break; 354 break;
317 } 355 }
318 } 356 }
319 357
320 void BrowserPluginGuest::SendMessageToEmbedder(IPC::Message* msg) { 358 void BrowserPluginGuest::SendMessageToEmbedder(IPC::Message* msg) {
321 DCHECK(embedder_render_process_host()); 359 DCHECK(embedder_render_process_host());
322 embedder_render_process_host()->Send(msg); 360 embedder_render_process_host()->Send(msg);
323 } 361 }
324 362
325 } // namespace content 363 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698