| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "extensions/browser/guest_view/mime_handler_view/mime_handler_view_gues
t.h" | 5 #include "extensions/browser/guest_view/mime_handler_view/mime_handler_view_gues
t.h" |
| 6 | 6 |
| 7 #include "base/strings/stringprintf.h" | 7 #include "base/strings/stringprintf.h" |
| 8 #include "content/public/browser/browser_thread.h" | 8 #include "content/public/browser/browser_thread.h" |
| 9 #include "content/public/browser/render_process_host.h" | 9 #include "content/public/browser/render_process_host.h" |
| 10 #include "content/public/common/url_constants.h" | 10 #include "content/public/common/url_constants.h" |
| 11 #include "extensions/browser/api/extensions_api_client.h" |
| 11 #include "extensions/browser/guest_view/guest_view_constants.h" | 12 #include "extensions/browser/guest_view/guest_view_constants.h" |
| 12 #include "extensions/browser/guest_view/guest_view_manager.h" | 13 #include "extensions/browser/guest_view/guest_view_manager.h" |
| 13 #include "extensions/browser/guest_view/mime_handler_view/mime_handler_view_cons
tants.h" | 14 #include "extensions/browser/guest_view/mime_handler_view/mime_handler_view_cons
tants.h" |
| 15 #include "extensions/browser/guest_view/mime_handler_view/mime_handler_view_gues
t_delegate.h" |
| 14 #include "extensions/common/feature_switch.h" | 16 #include "extensions/common/feature_switch.h" |
| 15 #include "extensions/strings/grit/extensions_strings.h" | 17 #include "extensions/strings/grit/extensions_strings.h" |
| 16 #include "net/base/url_util.h" | 18 #include "net/base/url_util.h" |
| 17 | 19 |
| 18 using content::WebContents; | 20 using content::WebContents; |
| 19 | 21 |
| 20 namespace extensions { | 22 namespace extensions { |
| 21 | 23 |
| 22 // static | 24 // static |
| 23 const char MimeHandlerViewGuest::Type[] = "mimehandler"; | 25 const char MimeHandlerViewGuest::Type[] = "mimehandler"; |
| 24 | 26 |
| 25 // static | 27 // static |
| 26 GuestViewBase* MimeHandlerViewGuest::Create( | 28 GuestViewBase* MimeHandlerViewGuest::Create( |
| 27 content::BrowserContext* browser_context, | 29 content::BrowserContext* browser_context, |
| 28 int guest_instance_id) { | 30 int guest_instance_id) { |
| 29 if (!extensions::FeatureSwitch::mime_handler_view()->IsEnabled()) | 31 if (!extensions::FeatureSwitch::mime_handler_view()->IsEnabled()) |
| 30 return NULL; | 32 return NULL; |
| 31 | 33 |
| 32 return new MimeHandlerViewGuest(browser_context, guest_instance_id); | 34 return new MimeHandlerViewGuest(browser_context, guest_instance_id); |
| 33 } | 35 } |
| 34 | 36 |
| 35 MimeHandlerViewGuest::MimeHandlerViewGuest( | 37 MimeHandlerViewGuest::MimeHandlerViewGuest( |
| 36 content::BrowserContext* browser_context, | 38 content::BrowserContext* browser_context, |
| 37 int guest_instance_id) | 39 int guest_instance_id) |
| 38 : GuestView<MimeHandlerViewGuest>(browser_context, guest_instance_id) { | 40 : GuestView<MimeHandlerViewGuest>(browser_context, guest_instance_id), |
| 41 delegate_(ExtensionsAPIClient::Get()->CreateMimeHandlerViewGuestDelegate( |
| 42 this)) { |
| 39 } | 43 } |
| 40 | 44 |
| 41 MimeHandlerViewGuest::~MimeHandlerViewGuest() { | 45 MimeHandlerViewGuest::~MimeHandlerViewGuest() { |
| 42 } | 46 } |
| 43 | 47 |
| 44 const char* MimeHandlerViewGuest::GetAPINamespace() const { | 48 const char* MimeHandlerViewGuest::GetAPINamespace() const { |
| 45 return "mimeHandlerViewGuestInternal"; | 49 return "mimeHandlerViewGuestInternal"; |
| 46 } | 50 } |
| 47 | 51 |
| 48 int MimeHandlerViewGuest::GetTaskPrefix() const { | 52 int MimeHandlerViewGuest::GetTaskPrefix() const { |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 87 std::string src; | 91 std::string src; |
| 88 bool success = attach_params()->GetString(mime_handler_view::kSrc, &src); | 92 bool success = attach_params()->GetString(mime_handler_view::kSrc, &src); |
| 89 DCHECK(success && !src.empty()); | 93 DCHECK(success && !src.empty()); |
| 90 web_contents()->GetController().LoadURL( | 94 web_contents()->GetController().LoadURL( |
| 91 GURL(src), | 95 GURL(src), |
| 92 content::Referrer(), | 96 content::Referrer(), |
| 93 content::PAGE_TRANSITION_AUTO_TOPLEVEL, | 97 content::PAGE_TRANSITION_AUTO_TOPLEVEL, |
| 94 std::string()); | 98 std::string()); |
| 95 } | 99 } |
| 96 | 100 |
| 101 void MimeHandlerViewGuest::DidInitialize() { |
| 102 if (delegate_) |
| 103 delegate_->AttachHelpers(); |
| 104 } |
| 105 |
| 97 void MimeHandlerViewGuest::HandleKeyboardEvent( | 106 void MimeHandlerViewGuest::HandleKeyboardEvent( |
| 98 WebContents* source, | 107 WebContents* source, |
| 99 const content::NativeWebKeyboardEvent& event) { | 108 const content::NativeWebKeyboardEvent& event) { |
| 100 if (!attached()) | 109 if (!attached()) |
| 101 return; | 110 return; |
| 102 | 111 |
| 103 // Send the keyboard events back to the embedder to reprocess them. | 112 // Send the keyboard events back to the embedder to reprocess them. |
| 104 // TODO(fsamuel): This introduces the possibility of out-of-order keyboard | 113 // TODO(fsamuel): This introduces the possibility of out-of-order keyboard |
| 105 // events because the guest may be arbitrarily delayed when responding to | 114 // events because the guest may be arbitrarily delayed when responding to |
| 106 // keyboard events. In that time, the embedder may have received and processed | 115 // keyboard events. In that time, the embedder may have received and processed |
| 107 // additional key events. This needs to be fixed as soon as possible. | 116 // additional key events. This needs to be fixed as soon as possible. |
| 108 // See http://crbug.com/229882. | 117 // See http://crbug.com/229882. |
| 109 embedder_web_contents()->GetDelegate()->HandleKeyboardEvent(web_contents(), | 118 embedder_web_contents()->GetDelegate()->HandleKeyboardEvent(web_contents(), |
| 110 event); | 119 event); |
| 111 } | 120 } |
| 112 | 121 |
| 113 } // namespace extensions | 122 } // namespace extensions |
| OLD | NEW |