OLD | NEW |
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 "base/string_util.h" | 9 #include "base/string_util.h" |
10 #include "content/browser/browser_plugin/browser_plugin_guest_helper.h" | 10 #include "content/browser/browser_plugin/browser_plugin_guest_helper.h" |
11 #include "content/browser/browser_plugin/browser_plugin_host_factory.h" | 11 #include "content/browser/browser_plugin/browser_plugin_host_factory.h" |
12 #include "content/browser/renderer_host/render_view_host_impl.h" | 12 #include "content/browser/renderer_host/render_view_host_impl.h" |
13 #include "content/browser/renderer_host/render_widget_host_impl.h" | 13 #include "content/browser/renderer_host/render_widget_host_impl.h" |
14 #include "content/browser/web_contents/web_contents_impl.h" | 14 #include "content/browser/web_contents/web_contents_impl.h" |
15 #include "content/common/browser_plugin_messages.h" | 15 #include "content/common/browser_plugin_messages.h" |
16 #include "content/common/view_messages.h" | 16 #include "content/common/view_messages.h" |
| 17 #include "content/public/browser/notification_service.h" |
| 18 #include "content/public/browser/notification_types.h" |
17 #include "content/public/browser/render_process_host.h" | 19 #include "content/public/browser/render_process_host.h" |
18 #include "content/public/browser/render_widget_host_view.h" | 20 #include "content/public/browser/render_widget_host_view.h" |
| 21 #include "content/public/browser/resource_request_details.h" |
19 #include "content/public/browser/user_metrics.h" | 22 #include "content/public/browser/user_metrics.h" |
20 #include "content/public/common/result_codes.h" | 23 #include "content/public/common/result_codes.h" |
21 #include "content/browser/browser_plugin/browser_plugin_host_factory.h" | 24 #include "content/browser/browser_plugin/browser_plugin_host_factory.h" |
22 #include "net/base/net_errors.h" | 25 #include "net/base/net_errors.h" |
23 #include "ui/surface/transport_dib.h" | 26 #include "ui/surface/transport_dib.h" |
| 27 #include "webkit/glue/resource_type.h" |
24 | 28 |
25 namespace content { | 29 namespace content { |
26 | 30 |
27 // static | 31 // static |
28 BrowserPluginHostFactory* BrowserPluginGuest::factory_ = NULL; | 32 BrowserPluginHostFactory* BrowserPluginGuest::factory_ = NULL; |
29 | 33 |
30 namespace { | 34 namespace { |
31 const int kGuestHangTimeoutMs = 5000; | 35 const int kGuestHangTimeoutMs = 5000; |
32 } | 36 } |
33 | 37 |
34 BrowserPluginGuest::BrowserPluginGuest(int instance_id, | 38 BrowserPluginGuest::BrowserPluginGuest(int instance_id, |
35 WebContentsImpl* web_contents, | 39 WebContentsImpl* web_contents, |
36 RenderViewHost* render_view_host) | 40 RenderViewHost* render_view_host) |
37 : WebContentsObserver(web_contents), | 41 : WebContentsObserver(web_contents), |
38 embedder_render_process_host_(NULL), | 42 embedder_render_process_host_(NULL), |
39 instance_id_(instance_id), | 43 instance_id_(instance_id), |
40 #if defined(OS_WIN) | 44 #if defined(OS_WIN) |
41 damage_buffer_size_(0), | 45 damage_buffer_size_(0), |
42 #endif | 46 #endif |
43 damage_buffer_scale_factor_(1.0f), | 47 damage_buffer_scale_factor_(1.0f), |
44 pending_update_counter_(0), | 48 pending_update_counter_(0), |
45 guest_hang_timeout_( | 49 guest_hang_timeout_( |
46 base::TimeDelta::FromMilliseconds(kGuestHangTimeoutMs)) { | 50 base::TimeDelta::FromMilliseconds(kGuestHangTimeoutMs)) { |
47 DCHECK(web_contents); | 51 DCHECK(web_contents); |
48 // |render_view_host| manages the ownership of this BrowserPluginGuestHelper. | 52 // |render_view_host| manages the ownership of this BrowserPluginGuestHelper. |
49 new BrowserPluginGuestHelper(this, render_view_host); | 53 new BrowserPluginGuestHelper(this, render_view_host); |
| 54 |
| 55 notification_registrar_.Add( |
| 56 this, content::NOTIFICATION_RESOURCE_RECEIVED_REDIRECT, |
| 57 content::Source<content::WebContents>(web_contents)); |
50 } | 58 } |
51 | 59 |
52 BrowserPluginGuest::~BrowserPluginGuest() { | 60 BrowserPluginGuest::~BrowserPluginGuest() { |
53 } | 61 } |
54 | 62 |
55 // static | 63 // static |
56 BrowserPluginGuest* BrowserPluginGuest::Create( | 64 BrowserPluginGuest* BrowserPluginGuest::Create( |
57 int instance_id, | 65 int instance_id, |
58 WebContentsImpl* web_contents, | 66 WebContentsImpl* web_contents, |
59 content::RenderViewHost* render_view_host) { | 67 content::RenderViewHost* render_view_host) { |
60 RecordAction(UserMetricsAction("BrowserPlugin.Guest.Create")); | 68 RecordAction(UserMetricsAction("BrowserPlugin.Guest.Create")); |
61 if (factory_) { | 69 if (factory_) { |
62 return factory_->CreateBrowserPluginGuest(instance_id, | 70 return factory_->CreateBrowserPluginGuest(instance_id, |
63 web_contents, | 71 web_contents, |
64 render_view_host); | 72 render_view_host); |
65 } | 73 } |
66 return new BrowserPluginGuest(instance_id, web_contents, render_view_host); | 74 return new BrowserPluginGuest(instance_id, web_contents, render_view_host); |
67 } | 75 } |
68 | 76 |
| 77 void BrowserPluginGuest::Observe(int type, |
| 78 const NotificationSource& source, |
| 79 const NotificationDetails& details) { |
| 80 switch (type) { |
| 81 case NOTIFICATION_RESOURCE_RECEIVED_REDIRECT: { |
| 82 DCHECK_EQ(Source<WebContents>(source).ptr(), web_contents()); |
| 83 ResourceRedirectDetails* resource_redirect_details = |
| 84 Details<ResourceRedirectDetails>(details).ptr(); |
| 85 bool is_top_level = |
| 86 resource_redirect_details->resource_type == ResourceType::MAIN_FRAME; |
| 87 LoadRedirect(resource_redirect_details->url, |
| 88 resource_redirect_details->new_url, |
| 89 is_top_level); |
| 90 break; |
| 91 } |
| 92 default: |
| 93 NOTREACHED() << "Unexpected notification sent."; |
| 94 break; |
| 95 } |
| 96 } |
| 97 |
69 bool BrowserPluginGuest::ViewTakeFocus(bool reverse) { | 98 bool BrowserPluginGuest::ViewTakeFocus(bool reverse) { |
70 SendMessageToEmbedder( | 99 SendMessageToEmbedder( |
71 new BrowserPluginMsg_AdvanceFocus(instance_id(), reverse)); | 100 new BrowserPluginMsg_AdvanceFocus(instance_id(), reverse)); |
72 return true; | 101 return true; |
73 } | 102 } |
74 | 103 |
75 void BrowserPluginGuest::Go(int relative_index) { | 104 void BrowserPluginGuest::Go(int relative_index) { |
76 web_contents()->GetController().GoToOffset(relative_index); | 105 web_contents()->GetController().GoToOffset(relative_index); |
77 } | 106 } |
78 | 107 |
(...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
314 std::string error_type; | 343 std::string error_type; |
315 RemoveChars(net::ErrorToString(error_code), "net::", &error_type); | 344 RemoveChars(net::ErrorToString(error_code), "net::", &error_type); |
316 // Inform the embedder of the loadAbort. | 345 // Inform the embedder of the loadAbort. |
317 SendMessageToEmbedder( | 346 SendMessageToEmbedder( |
318 new BrowserPluginMsg_LoadAbort(instance_id(), | 347 new BrowserPluginMsg_LoadAbort(instance_id(), |
319 validated_url, | 348 validated_url, |
320 is_main_frame, | 349 is_main_frame, |
321 error_type)); | 350 error_type)); |
322 } | 351 } |
323 | 352 |
| 353 void BrowserPluginGuest::LoadRedirect( |
| 354 const GURL& old_url, |
| 355 const GURL& new_url, |
| 356 bool is_top_level) { |
| 357 SendMessageToEmbedder( |
| 358 new BrowserPluginMsg_LoadRedirect( |
| 359 instance_id(), old_url, new_url, is_top_level)); |
| 360 } |
| 361 |
324 void BrowserPluginGuest::DidCommitProvisionalLoadForFrame( | 362 void BrowserPluginGuest::DidCommitProvisionalLoadForFrame( |
325 int64 frame_id, | 363 int64 frame_id, |
326 bool is_main_frame, | 364 bool is_main_frame, |
327 const GURL& url, | 365 const GURL& url, |
328 PageTransition transition_type, | 366 PageTransition transition_type, |
329 RenderViewHost* render_view_host) { | 367 RenderViewHost* render_view_host) { |
330 // Inform its embedder of the updated URL. | 368 // Inform its embedder of the updated URL. |
331 if (is_main_frame) { | 369 if (is_main_frame) { |
332 SendMessageToEmbedder( | 370 SendMessageToEmbedder( |
333 new BrowserPluginMsg_DidNavigate( | 371 new BrowserPluginMsg_DidNavigate( |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
367 break; | 405 break; |
368 } | 406 } |
369 } | 407 } |
370 | 408 |
371 void BrowserPluginGuest::SendMessageToEmbedder(IPC::Message* msg) { | 409 void BrowserPluginGuest::SendMessageToEmbedder(IPC::Message* msg) { |
372 DCHECK(embedder_render_process_host()); | 410 DCHECK(embedder_render_process_host()); |
373 embedder_render_process_host()->Send(msg); | 411 embedder_render_process_host()->Send(msg); |
374 } | 412 } |
375 | 413 |
376 } // namespace content | 414 } // namespace content |
OLD | NEW |