Index: content/renderer/browser_plugin/browser_plugin_impl.cc |
diff --git a/content/renderer/browser_plugin/browser_plugin.cc b/content/renderer/browser_plugin/browser_plugin_impl.cc |
similarity index 80% |
rename from content/renderer/browser_plugin/browser_plugin.cc |
rename to content/renderer/browser_plugin/browser_plugin_impl.cc |
index 573ff76bb1de82c478ea0952b5e622681b2d0175..716a6927a2662ecd1859266d68fc98e357b18aa6 100644 |
--- a/content/renderer/browser_plugin/browser_plugin.cc |
+++ b/content/renderer/browser_plugin/browser_plugin_impl.cc |
@@ -2,7 +2,7 @@ |
// Use of this source code is governed by a BSD-style license that can be |
// found in the LICENSE file. |
-#include "content/renderer/browser_plugin/browser_plugin.h" |
+#include "content/renderer/browser_plugin/browser_plugin_impl.h" |
#include "base/json/json_string_value_serializer.h" |
#include "base/message_loop.h" |
@@ -12,6 +12,7 @@ |
#include "content/common/browser_plugin_messages.h" |
#include "content/common/view_messages.h" |
#include "content/public/common/content_client.h" |
+#include "content/public/renderer/browser_plugin/browser_plugin_observer.h" |
#include "content/public/renderer/content_renderer_client.h" |
#include "content/renderer/browser_plugin/browser_plugin_bindings.h" |
#include "content/renderer/browser_plugin/browser_plugin_compositing_helper.h" |
@@ -72,7 +73,7 @@ static std::string GetInternalEventName(const char* event_name) { |
} |
} // namespace |
-BrowserPlugin::BrowserPlugin( |
+BrowserPluginImpl::BrowserPluginImpl( |
RenderViewImpl* render_view, |
WebKit::WebFrame* frame, |
const WebPluginParams& params) |
@@ -101,9 +102,10 @@ BrowserPlugin::BrowserPlugin( |
compositing_enabled_(false), |
ALLOW_THIS_IN_INITIALIZER_LIST( |
weak_ptr_factory_(this)) { |
+ GetContentClient()->renderer()->BrowserPluginCreated(this); |
} |
-BrowserPlugin::~BrowserPlugin() { |
+BrowserPluginImpl::~BrowserPluginImpl() { |
// If the BrowserPlugin has never navigated then the browser process and |
// BrowserPluginManager don't know about it and so there is nothing to do |
// here. |
@@ -115,11 +117,20 @@ BrowserPlugin::~BrowserPlugin() { |
instance_id_)); |
} |
-bool BrowserPlugin::OnMessageReceived(const IPC::Message& message) { |
+void BrowserPluginImpl::AddObserver(BrowserPluginObserver* observer) { |
+ observers_.AddObserver(observer); |
+} |
+ |
+void BrowserPluginImpl::RemoveObserver(BrowserPluginObserver* observer) { |
+ observers_.RemoveObserver(observer); |
+} |
+ |
+bool BrowserPluginImpl::OnMessageReceived(const IPC::Message& message) { |
bool handled = true; |
- IPC_BEGIN_MESSAGE_MAP(BrowserPlugin, message) |
+ IPC_BEGIN_MESSAGE_MAP(BrowserPluginImpl, message) |
IPC_MESSAGE_HANDLER(BrowserPluginMsg_AdvanceFocus, OnAdvanceFocus) |
IPC_MESSAGE_HANDLER(BrowserPluginMsg_BuffersSwapped, OnBuffersSwapped) |
+ IPC_MESSAGE_HANDLER(BrowserPluginMsg_ForwardMessage, OnForwardMessage) |
IPC_MESSAGE_HANDLER(BrowserPluginMsg_GuestContentWindowReady, |
OnGuestContentWindowReady) |
IPC_MESSAGE_HANDLER(BrowserPluginMsg_GuestGone, OnGuestGone) |
@@ -141,98 +152,57 @@ bool BrowserPlugin::OnMessageReceived(const IPC::Message& message) { |
return handled; |
} |
-void BrowserPlugin::UpdateDOMAttribute(const std::string& attribute_name, |
- const std::string& attribute_value) { |
- if (!container()) |
- return; |
- |
- WebKit::WebElement element = container()->element(); |
- WebKit::WebString web_attribute_name = |
- WebKit::WebString::fromUTF8(attribute_name); |
- if (!HasDOMAttribute(attribute_name) || |
- (std::string(element.getAttribute(web_attribute_name).utf8()) != |
- attribute_value)) { |
- element.setAttribute(web_attribute_name, |
- WebKit::WebString::fromUTF8(attribute_value)); |
- } |
-} |
- |
-void BrowserPlugin::RemoveDOMAttribute(const std::string& attribute_name) { |
- if (!container()) |
- return; |
- |
- container()->element().removeAttribute( |
- WebKit::WebString::fromUTF8(attribute_name)); |
-} |
- |
-std::string BrowserPlugin::GetDOMAttributeValue( |
- const std::string& attribute_name) const { |
- if (!container()) |
- return ""; |
- |
- return container()->element().getAttribute( |
- WebKit::WebString::fromUTF8(attribute_name)).utf8(); |
-} |
- |
-bool BrowserPlugin::HasDOMAttribute(const std::string& attribute_name) const { |
- if (!container()) |
- return false; |
- |
- return container()->element().hasAttribute( |
- WebKit::WebString::fromUTF8(attribute_name)); |
-} |
- |
-std::string BrowserPlugin::GetNameAttribute() const { |
+std::string BrowserPluginImpl::GetNameAttribute() const { |
return GetDOMAttributeValue(browser_plugin::kAttributeName); |
} |
-std::string BrowserPlugin::GetSrcAttribute() const { |
+std::string BrowserPluginImpl::GetSrcAttribute() const { |
return GetDOMAttributeValue(browser_plugin::kAttributeSrc); |
} |
-bool BrowserPlugin::GetAutoSizeAttribute() const { |
+bool BrowserPluginImpl::GetAutoSizeAttribute() const { |
return HasDOMAttribute(browser_plugin::kAttributeAutoSize); |
} |
-int BrowserPlugin::GetMaxHeightAttribute() const { |
+int BrowserPluginImpl::GetMaxHeightAttribute() const { |
int max_height; |
base::StringToInt(GetDOMAttributeValue(browser_plugin::kAttributeMaxHeight), |
&max_height); |
return max_height; |
} |
-int BrowserPlugin::GetMaxWidthAttribute() const { |
+int BrowserPluginImpl::GetMaxWidthAttribute() const { |
int max_width; |
base::StringToInt(GetDOMAttributeValue(browser_plugin::kAttributeMaxWidth), |
&max_width); |
return max_width; |
} |
-int BrowserPlugin::GetMinHeightAttribute() const { |
+int BrowserPluginImpl::GetMinHeightAttribute() const { |
int min_height; |
base::StringToInt(GetDOMAttributeValue(browser_plugin::kAttributeMinHeight), |
&min_height); |
return min_height; |
} |
-int BrowserPlugin::GetMinWidthAttribute() const { |
+int BrowserPluginImpl::GetMinWidthAttribute() const { |
int min_width; |
base::StringToInt(GetDOMAttributeValue(browser_plugin::kAttributeMinWidth), |
&min_width); |
return min_width; |
} |
-int BrowserPlugin::GetAdjustedMaxHeight() const { |
+int BrowserPluginImpl::GetAdjustedMaxHeight() const { |
int max_height = GetMaxHeightAttribute(); |
return max_height ? max_height : height(); |
} |
-int BrowserPlugin::GetAdjustedMaxWidth() const { |
+int BrowserPluginImpl::GetAdjustedMaxWidth() const { |
int max_width = GetMaxWidthAttribute(); |
return max_width ? max_width : width(); |
} |
-int BrowserPlugin::GetAdjustedMinHeight() const { |
+int BrowserPluginImpl::GetAdjustedMinHeight() const { |
int min_height = GetMinHeightAttribute(); |
// FrameView.cpp does not allow this value to be <= 0, so when the value is |
// unset (or set to 0), we set it to the container size. |
@@ -241,7 +211,7 @@ int BrowserPlugin::GetAdjustedMinHeight() const { |
return std::min(min_height, GetAdjustedMaxHeight()); |
} |
-int BrowserPlugin::GetAdjustedMinWidth() const { |
+int BrowserPluginImpl::GetAdjustedMinWidth() const { |
int min_width = GetMinWidthAttribute(); |
// FrameView.cpp does not allow this value to be <= 0, so when the value is |
// unset (or set to 0), we set it to the container size. |
@@ -250,11 +220,11 @@ int BrowserPlugin::GetAdjustedMinWidth() const { |
return std::min(min_width, GetAdjustedMaxWidth()); |
} |
-std::string BrowserPlugin::GetPartitionAttribute() const { |
+std::string BrowserPluginImpl::GetPartitionAttribute() const { |
return GetDOMAttributeValue(browser_plugin::kAttributePartition); |
} |
-void BrowserPlugin::ParseNameAttribute() { |
+void BrowserPluginImpl::ParseNameAttribute() { |
if (!navigate_src_sent_) |
return; |
browser_plugin_manager()->Send( |
@@ -263,7 +233,7 @@ void BrowserPlugin::ParseNameAttribute() { |
GetNameAttribute())); |
} |
-bool BrowserPlugin::ParseSrcAttribute(std::string* error_message) { |
+bool BrowserPluginImpl::ParseSrcAttribute(std::string* error_message) { |
if (!valid_partition_id_) { |
*error_message = browser_plugin::kErrorInvalidPartition; |
return false; |
@@ -299,13 +269,13 @@ bool BrowserPlugin::ParseSrcAttribute(std::string* error_message) { |
return true; |
} |
-void BrowserPlugin::ParseAutoSizeAttribute() { |
+void BrowserPluginImpl::ParseAutoSizeAttribute() { |
auto_size_ack_pending_ = true; |
last_view_size_ = plugin_rect_.size(); |
UpdateGuestAutoSizeState(GetAutoSizeAttribute()); |
} |
-void BrowserPlugin::PopulateAutoSizeParameters( |
+void BrowserPluginImpl::PopulateAutoSizeParameters( |
BrowserPluginHostMsg_AutoSize_Params* params, bool current_auto_size) { |
params->enable = current_auto_size; |
// No need to populate the params if autosize is off. |
@@ -315,10 +285,10 @@ void BrowserPlugin::PopulateAutoSizeParameters( |
} |
} |
-void BrowserPlugin::UpdateGuestAutoSizeState(bool current_auto_size) { |
+void BrowserPluginImpl::UpdateGuestAutoSizeState(bool current_auto_size) { |
// If we haven't yet heard back from the guest about the last resize request, |
// then we don't issue another request until we do in |
- // BrowserPlugin::UpdateRect. |
+ // BrowserPluginImpl::UpdateRect. |
if (!navigate_src_sent_ || !resize_ack_received_) |
return; |
BrowserPluginHostMsg_AutoSize_Params auto_size_params; |
@@ -336,7 +306,8 @@ void BrowserPlugin::UpdateGuestAutoSizeState(bool current_auto_size) { |
resize_guest_params)); |
} |
-void BrowserPlugin::SizeChangedDueToAutoSize(const gfx::Size& old_view_size) { |
+void BrowserPluginImpl::SizeChangedDueToAutoSize( |
+ const gfx::Size& old_view_size) { |
size_changed_in_flight_ = false; |
std::map<std::string, base::Value*> props; |
@@ -352,19 +323,19 @@ void BrowserPlugin::SizeChangedDueToAutoSize(const gfx::Size& old_view_size) { |
} |
// static |
-bool BrowserPlugin::UsesDamageBuffer( |
+bool BrowserPluginImpl::UsesDamageBuffer( |
const BrowserPluginMsg_UpdateRect_Params& params) { |
return params.damage_buffer_sequence_id != 0 || params.needs_ack; |
} |
-bool BrowserPlugin::UsesPendingDamageBuffer( |
+bool BrowserPluginImpl::UsesPendingDamageBuffer( |
const BrowserPluginMsg_UpdateRect_Params& params) { |
if (!pending_damage_buffer_.get()) |
return false; |
return damage_buffer_sequence_id_ == params.damage_buffer_sequence_id; |
} |
-void BrowserPlugin::SetInstanceID(int instance_id) { |
+void BrowserPluginImpl::SetInstanceID(int instance_id) { |
CHECK(instance_id != browser_plugin::kInstanceIDNone); |
instance_id_ = instance_id; |
browser_plugin_manager()->AddBrowserPlugin(instance_id, this); |
@@ -389,16 +360,16 @@ void BrowserPlugin::SetInstanceID(int instance_id) { |
navigate_src_sent_ = true; |
} |
-void BrowserPlugin::OnAdvanceFocus(int instance_id, bool reverse) { |
+void BrowserPluginImpl::OnAdvanceFocus(int instance_id, bool reverse) { |
DCHECK(render_view_); |
render_view_->GetWebView()->advanceFocus(reverse); |
} |
-void BrowserPlugin::OnBuffersSwapped(int instance_id, |
- const gfx::Size& size, |
- std::string mailbox_name, |
- int gpu_route_id, |
- int gpu_host_id) { |
+void BrowserPluginImpl::OnBuffersSwapped(int instance_id, |
+ const gfx::Size& size, |
+ std::string mailbox_name, |
+ int gpu_route_id, |
+ int gpu_host_id) { |
DCHECK(instance_id == instance_id_); |
EnableCompositing(true); |
@@ -408,13 +379,28 @@ void BrowserPlugin::OnBuffersSwapped(int instance_id, |
gpu_host_id); |
} |
-void BrowserPlugin::OnGuestContentWindowReady(int instance_id, |
- int content_window_routing_id) { |
+void BrowserPluginImpl::OnForwardMessage(int instance_id, |
+ const IPC::Message& msg) { |
+ if (!observers_.might_have_observers()) |
+ return; |
+ ObserverListBase<BrowserPluginObserver>::Iterator it(observers_); |
+ BrowserPluginObserver* observer; |
+ while ((observer = it.GetNext()) != NULL) { |
+ if (observer->OnMessageReceived(msg)) |
+ return; |
+ } |
+} |
+ |
+void BrowserPluginImpl::OnGuestContentWindowReady( |
+ int instance_id, |
+ int content_window_routing_id) { |
DCHECK(content_window_routing_id != MSG_ROUTING_NONE); |
content_window_routing_id_ = content_window_routing_id; |
} |
-void BrowserPlugin::OnGuestGone(int instance_id, int process_id, int status) { |
+void BrowserPluginImpl::OnGuestGone(int instance_id, |
+ int process_id, |
+ int status) { |
// Set the BrowserPlugin in a crashed state before firing event listeners so |
// that operations on the BrowserPlugin within listeners are aware that |
// BrowserPlugin is in a crashed state. |
@@ -430,7 +416,7 @@ void BrowserPlugin::OnGuestGone(int instance_id, int process_id, int status) { |
// Event listeners may remove the BrowserPlugin from the document. If that |
// happens, the BrowserPlugin will be scheduled for later deletion (see |
- // BrowserPlugin::destroy()). That will clear the container_ reference, |
+ // BrowserPluginImpl::destroy()). That will clear the container_ reference, |
// but leave other member variables valid below. |
TriggerEvent(browser_plugin::kEventExit, &props); |
@@ -445,22 +431,22 @@ void BrowserPlugin::OnGuestGone(int instance_id, int process_id, int status) { |
EnableCompositing(false); |
} |
-void BrowserPlugin::OnGuestResponsive(int instance_id, int process_id) { |
+void BrowserPluginImpl::OnGuestResponsive(int instance_id, int process_id) { |
std::map<std::string, base::Value*> props; |
props[browser_plugin::kProcessId] = new base::FundamentalValue(process_id); |
TriggerEvent(browser_plugin::kEventResponsive, &props); |
} |
-void BrowserPlugin::OnGuestUnresponsive(int instance_id, int process_id) { |
+void BrowserPluginImpl::OnGuestUnresponsive(int instance_id, int process_id) { |
std::map<std::string, base::Value*> props; |
props[browser_plugin::kProcessId] = new base::FundamentalValue(process_id); |
TriggerEvent(browser_plugin::kEventUnresponsive, &props); |
} |
-void BrowserPlugin::OnLoadAbort(int instance_id, |
- const GURL& url, |
- bool is_top_level, |
- const std::string& type) { |
+void BrowserPluginImpl::OnLoadAbort(int instance_id, |
+ const GURL& url, |
+ bool is_top_level, |
+ const std::string& type) { |
std::map<std::string, base::Value*> props; |
props[browser_plugin::kURL] = new base::StringValue(url.spec()); |
props[browser_plugin::kIsTopLevel] = new base::FundamentalValue(is_top_level); |
@@ -468,7 +454,7 @@ void BrowserPlugin::OnLoadAbort(int instance_id, |
TriggerEvent(browser_plugin::kEventLoadAbort, &props); |
} |
-void BrowserPlugin::OnLoadCommit( |
+void BrowserPluginImpl::OnLoadCommit( |
int instance_id, |
const BrowserPluginMsg_LoadCommit_Params& params) { |
// If the guest has just committed a new navigation then it is no longer |
@@ -489,10 +475,10 @@ void BrowserPlugin::OnLoadCommit( |
TriggerEvent(browser_plugin::kEventLoadCommit, &props); |
} |
-void BrowserPlugin::OnLoadRedirect(int instance_id, |
- const GURL& old_url, |
- const GURL& new_url, |
- bool is_top_level) { |
+void BrowserPluginImpl::OnLoadRedirect(int instance_id, |
+ const GURL& old_url, |
+ const GURL& new_url, |
+ bool is_top_level) { |
std::map<std::string, base::Value*> props; |
props[browser_plugin::kOldURL] = new base::StringValue(old_url.spec()); |
props[browser_plugin::kNewURL] = new base::StringValue(new_url.spec()); |
@@ -500,9 +486,9 @@ void BrowserPlugin::OnLoadRedirect(int instance_id, |
TriggerEvent(browser_plugin::kEventLoadRedirect, &props); |
} |
-void BrowserPlugin::OnLoadStart(int instance_id, |
- const GURL& url, |
- bool is_top_level) { |
+void BrowserPluginImpl::OnLoadStart(int instance_id, |
+ const GURL& url, |
+ bool is_top_level) { |
std::map<std::string, base::Value*> props; |
props[browser_plugin::kURL] = new base::StringValue(url.spec()); |
props[browser_plugin::kIsTopLevel] = new base::FundamentalValue(is_top_level); |
@@ -510,11 +496,11 @@ void BrowserPlugin::OnLoadStart(int instance_id, |
TriggerEvent(browser_plugin::kEventLoadStart, &props); |
} |
-void BrowserPlugin::OnLoadStop(int instance_id) { |
+void BrowserPluginImpl::OnLoadStop(int instance_id) { |
TriggerEvent(browser_plugin::kEventLoadStop, NULL); |
} |
-void BrowserPlugin::OnRequestPermission( |
+void BrowserPluginImpl::OnRequestPermission( |
int instance_id, |
BrowserPluginPermissionType permission_type, |
int request_id, |
@@ -523,11 +509,12 @@ void BrowserPlugin::OnRequestPermission( |
RequestMediaPermission(request_id, request_info); |
} |
-void BrowserPlugin::OnSetCursor(int instance_id, const WebCursor& cursor) { |
+void BrowserPluginImpl::OnSetCursor(int instance_id, const WebCursor& cursor) { |
cursor_ = cursor; |
} |
-void BrowserPlugin::OnShouldAcceptTouchEvents(int instance_id, bool accept) { |
+void BrowserPluginImpl::OnShouldAcceptTouchEvents(int instance_id, |
+ bool accept) { |
if (container()) { |
container()->requestTouchEventType(accept ? |
WebKit::WebPluginContainer::TouchEventRequestTypeRaw : |
@@ -535,11 +522,12 @@ void BrowserPlugin::OnShouldAcceptTouchEvents(int instance_id, bool accept) { |
} |
} |
-void BrowserPlugin::OnUpdatedName(int instance_id, const std::string& name) { |
+void BrowserPluginImpl::OnUpdatedName(int instance_id, |
+ const std::string& name) { |
UpdateDOMAttribute(browser_plugin::kAttributeName, name); |
} |
-void BrowserPlugin::RequestMediaPermission( |
+void BrowserPluginImpl::RequestMediaPermission( |
int request_id, const base::DictionaryValue& request_info) { |
if (!HasEventListeners(browser_plugin::kEventRequestPermission)) { |
// Automatically deny the request if there are no event listeners for |
@@ -568,7 +556,7 @@ void BrowserPlugin::RequestMediaPermission( |
TriggerEvent(browser_plugin::kEventRequestPermission, &props); |
} |
-bool BrowserPlugin::HasEventListeners(const std::string& event_name) { |
+bool BrowserPluginImpl::HasEventListeners(const std::string& event_name) { |
if (!container()) |
return false; |
@@ -588,7 +576,7 @@ bool BrowserPlugin::HasEventListeners(const std::string& event_name) { |
return false; |
} |
-void BrowserPlugin::OnUpdateRect( |
+void BrowserPluginImpl::OnUpdateRect( |
int instance_id, |
const BrowserPluginMsg_UpdateRect_Params& params) { |
bool use_new_damage_buffer = !backing_store_; |
@@ -665,7 +653,7 @@ void BrowserPlugin::OnUpdateRect( |
size_changed_in_flight_ = true; |
MessageLoop::current()->PostTask( |
FROM_HERE, |
- base::Bind(&BrowserPlugin::SizeChangedDueToAutoSize, |
+ base::Bind(&BrowserPluginImpl::SizeChangedDueToAutoSize, |
base::Unretained(this), |
old_view_size)); |
} |
@@ -716,18 +704,18 @@ void BrowserPlugin::OnUpdateRect( |
resize_guest_params)); |
} |
-void BrowserPlugin::ParseSizeContraintsChanged() { |
+void BrowserPluginImpl::ParseSizeContraintsChanged() { |
bool auto_size = GetAutoSizeAttribute(); |
if (auto_size) |
UpdateGuestAutoSizeState(true); |
} |
-bool BrowserPlugin::InAutoSizeBounds(const gfx::Size& size) const { |
+bool BrowserPluginImpl::InAutoSizeBounds(const gfx::Size& size) const { |
return size.width() <= GetAdjustedMaxWidth() && |
size.height() <= GetAdjustedMaxHeight(); |
} |
-NPObject* BrowserPlugin::GetContentWindow() const { |
+NPObject* BrowserPluginImpl::GetContentWindow() const { |
if (content_window_routing_id_ == MSG_ROUTING_NONE) |
return NULL; |
RenderViewImpl* guest_render_view = static_cast<RenderViewImpl*>( |
@@ -738,16 +726,16 @@ NPObject* BrowserPlugin::GetContentWindow() const { |
return guest_frame->windowObject(); |
} |
-bool BrowserPlugin::CanGoBack() const { |
+bool BrowserPluginImpl::CanGoBack() const { |
return nav_entry_count_ > 1 && current_nav_entry_index_ > 0; |
} |
-bool BrowserPlugin::CanGoForward() const { |
+bool BrowserPluginImpl::CanGoForward() const { |
return current_nav_entry_index_ >= 0 && |
current_nav_entry_index_ < (nav_entry_count_ - 1); |
} |
-bool BrowserPlugin::ParsePartitionAttribute(std::string* error_message) { |
+bool BrowserPluginImpl::ParsePartitionAttribute(std::string* error_message) { |
if (allocate_instance_id_sent_) { |
*error_message = browser_plugin::kErrorAlreadyNavigated; |
return false; |
@@ -779,13 +767,14 @@ bool BrowserPlugin::ParsePartitionAttribute(std::string* error_message) { |
return true; |
} |
-bool BrowserPlugin::CanRemovePartitionAttribute(std::string* error_message) { |
+bool BrowserPluginImpl::CanRemovePartitionAttribute( |
+ std::string* error_message) { |
if (navigate_src_sent_) |
*error_message = browser_plugin::kErrorCannotRemovePartition; |
return !navigate_src_sent_; |
} |
-void BrowserPlugin::ParseAttributes() { |
+void BrowserPluginImpl::ParseAttributes() { |
// TODO(mthiesse): Handle errors here? |
std::string error; |
ParsePartitionAttribute(&error); |
@@ -795,47 +784,13 @@ void BrowserPlugin::ParseAttributes() { |
ParseSrcAttribute(&error); |
} |
-float BrowserPlugin::GetDeviceScaleFactor() const { |
+float BrowserPluginImpl::GetDeviceScaleFactor() const { |
if (!render_view_) |
return 1.0f; |
return render_view_->GetWebView()->deviceScaleFactor(); |
} |
-void BrowserPlugin::TriggerEvent(const std::string& event_name, |
- std::map<std::string, base::Value*>* props) { |
- if (!container() || !container()->element().document().frame()) |
- return; |
- v8::HandleScope handle_scope; |
- std::string json_string; |
- if (props) { |
- base::DictionaryValue dict; |
- for (std::map<std::string, base::Value*>::iterator iter = props->begin(), |
- end = props->end(); iter != end; ++iter) { |
- dict.Set(iter->first, iter->second); |
- } |
- |
- JSONStringValueSerializer serializer(&json_string); |
- if (!serializer.Serialize(dict)) |
- return; |
- } |
- |
- WebKit::WebFrame* frame = container()->element().document().frame(); |
- WebKit::WebDOMEvent dom_event = frame->document().createEvent("CustomEvent"); |
- WebKit::WebDOMCustomEvent event = dom_event.to<WebKit::WebDOMCustomEvent>(); |
- |
- // The events triggered directly from the plugin <object> are internal events |
- // whose implementation details can (and likely will) change over time. The |
- // wrapper/shim (e.g. <webview> tag) should receive these events, and expose a |
- // more appropriate (and stable) event to the consumers as part of the API. |
- event.initCustomEvent( |
- WebKit::WebString::fromUTF8(GetInternalEventName(event_name.c_str())), |
- false, false, |
- WebKit::WebSerializedScriptValue::serialize( |
- v8::String::New(json_string.c_str(), json_string.size()))); |
- container()->element().dispatchEvent(event); |
-} |
- |
-void BrowserPlugin::OnRequestObjectGarbageCollected(int request_id) { |
+void BrowserPluginImpl::OnRequestObjectGarbageCollected(int request_id) { |
// Remove from alive objects. |
std::map<int, AliveV8PermissionRequestItem*>::iterator iter = |
alive_v8_permission_request_objects_.find(request_id); |
@@ -846,7 +801,7 @@ void BrowserPlugin::OnRequestObjectGarbageCollected(int request_id) { |
RespondPermissionIfRequestIsPending(request_id, false /*allow*/); |
} |
-void BrowserPlugin::PersistRequestObject( |
+void BrowserPluginImpl::PersistRequestObject( |
const NPVariant* request, const std::string& type, int id) { |
CHECK(alive_v8_permission_request_objects_.find(id) == |
alive_v8_permission_request_objects_.end()); |
@@ -859,7 +814,7 @@ void BrowserPlugin::PersistRequestObject( |
v8::Persistent<v8::Value>::New(WebKit::WebBindings::toV8Value(request)); |
AliveV8PermissionRequestItem* new_item = |
- new std::pair<int, base::WeakPtr<BrowserPlugin> >( |
+ new std::pair<int, base::WeakPtr<BrowserPluginImpl> >( |
id, weak_ptr_factory_.GetWeakPtr()); |
std::pair<std::map<int, AliveV8PermissionRequestItem*>::iterator, bool> |
@@ -871,7 +826,7 @@ void BrowserPlugin::PersistRequestObject( |
} |
// static |
-void BrowserPlugin::WeakCallbackForPersistObject( |
+void BrowserPluginImpl::WeakCallbackForPersistObject( |
v8::Persistent<v8::Value> object, void* param) { |
v8::Persistent<v8::Object> persistent_object = |
v8::Persistent<v8::Object>::Cast(object); |
@@ -879,7 +834,7 @@ void BrowserPlugin::WeakCallbackForPersistObject( |
AliveV8PermissionRequestItem* item_ptr = |
static_cast<AliveV8PermissionRequestItem*>(param); |
int request_id = item_ptr->first; |
- base::WeakPtr<BrowserPlugin> plugin = item_ptr->second; |
+ base::WeakPtr<BrowserPluginImpl> plugin = item_ptr->second; |
delete item_ptr; |
persistent_object.Dispose(); |
@@ -891,12 +846,12 @@ void BrowserPlugin::WeakCallbackForPersistObject( |
// don't need to worry about BrowserPlugin going away. |
MessageLoop::current()->PostTask( |
FROM_HERE, |
- base::Bind(&BrowserPlugin::OnRequestObjectGarbageCollected, |
+ base::Bind(&BrowserPluginImpl::OnRequestObjectGarbageCollected, |
plugin, request_id)); |
} |
} |
-void BrowserPlugin::Back() { |
+void BrowserPluginImpl::Back() { |
if (!navigate_src_sent_) |
return; |
browser_plugin_manager()->Send( |
@@ -904,7 +859,7 @@ void BrowserPlugin::Back() { |
instance_id_, -1)); |
} |
-void BrowserPlugin::Forward() { |
+void BrowserPluginImpl::Forward() { |
if (!navigate_src_sent_) |
return; |
browser_plugin_manager()->Send( |
@@ -912,7 +867,7 @@ void BrowserPlugin::Forward() { |
instance_id_, 1)); |
} |
-void BrowserPlugin::Go(int relative_index) { |
+void BrowserPluginImpl::Go(int relative_index) { |
if (!navigate_src_sent_) |
return; |
browser_plugin_manager()->Send( |
@@ -921,7 +876,7 @@ void BrowserPlugin::Go(int relative_index) { |
relative_index)); |
} |
-void BrowserPlugin::TerminateGuest() { |
+void BrowserPluginImpl::TerminateGuest() { |
if (!navigate_src_sent_ || guest_crashed_) |
return; |
browser_plugin_manager()->Send( |
@@ -929,7 +884,7 @@ void BrowserPlugin::TerminateGuest() { |
instance_id_)); |
} |
-void BrowserPlugin::Stop() { |
+void BrowserPluginImpl::Stop() { |
if (!navigate_src_sent_) |
return; |
browser_plugin_manager()->Send( |
@@ -937,7 +892,7 @@ void BrowserPlugin::Stop() { |
instance_id_)); |
} |
-void BrowserPlugin::Reload() { |
+void BrowserPluginImpl::Reload() { |
if (!navigate_src_sent_) |
return; |
browser_plugin_manager()->Send( |
@@ -945,7 +900,7 @@ void BrowserPlugin::Reload() { |
instance_id_)); |
} |
-void BrowserPlugin::UpdateGuestFocusState() { |
+void BrowserPluginImpl::UpdateGuestFocusState() { |
if (!navigate_src_sent_) |
return; |
bool should_be_focused = ShouldGuestBeFocused(); |
@@ -955,18 +910,18 @@ void BrowserPlugin::UpdateGuestFocusState() { |
should_be_focused)); |
} |
-bool BrowserPlugin::ShouldGuestBeFocused() const { |
+bool BrowserPluginImpl::ShouldGuestBeFocused() const { |
bool embedder_focused = false; |
if (render_view_) |
embedder_focused = render_view_->has_focus(); |
return plugin_focused_ && embedder_focused; |
} |
-WebKit::WebPluginContainer* BrowserPlugin::container() const { |
+WebKit::WebPluginContainer* BrowserPluginImpl::container() const { |
return container_; |
} |
-void BrowserPlugin::RespondPermission( |
+void BrowserPluginImpl::RespondPermission( |
BrowserPluginPermissionType permission_type, int request_id, bool allow) { |
switch (permission_type) { |
case BrowserPluginPermissionTypeMedia: |
@@ -983,7 +938,7 @@ void BrowserPlugin::RespondPermission( |
} |
} |
-void BrowserPlugin::RespondPermissionIfRequestIsPending( |
+void BrowserPluginImpl::RespondPermissionIfRequestIsPending( |
int request_id, bool allow) { |
PendingPermissionRequests::iterator iter = |
pending_permission_requests_.find(request_id); |
@@ -995,11 +950,12 @@ void BrowserPlugin::RespondPermissionIfRequestIsPending( |
RespondPermission(permission_type, request_id, allow); |
} |
-void BrowserPlugin::OnEmbedderDecidedPermission(int request_id, bool allow) { |
+void BrowserPluginImpl::OnEmbedderDecidedPermission(int request_id, |
+ bool allow) { |
RespondPermissionIfRequestIsPending(request_id, allow); |
} |
-bool BrowserPlugin::initialize(WebPluginContainer* container) { |
+bool BrowserPluginImpl::initialize(WebPluginContainer* container) { |
if (!container) |
return false; |
@@ -1013,7 +969,7 @@ bool BrowserPlugin::initialize(WebPluginContainer* container) { |
return true; |
} |
-void BrowserPlugin::EnableCompositing(bool enable) { |
+void BrowserPluginImpl::EnableCompositing(bool enable) { |
if (compositing_enabled_ == enable) |
return; |
@@ -1047,16 +1003,23 @@ void BrowserPlugin::EnableCompositing(bool enable) { |
compositing_helper_->EnableCompositing(enable); |
} |
-void BrowserPlugin::destroy() { |
+void BrowserPluginImpl::destroy() { |
// The BrowserPlugin's WebPluginContainer is deleted immediately after this |
// call returns, so let's not keep a reference to it around. |
container_ = NULL; |
+ // BrowserPluginObservers might create additional bindings. These bindings |
+ // might refer back to the observers that created them. In order to ensure |
+ // that bindings can always refer to valid observers, we get rid of bindings |
+ // prior to cleaning up observers. |
+ bindings_.reset(); |
+ FOR_EACH_OBSERVER(BrowserPluginObserver, observers_, BrowserPluginGone()); |
+ FOR_EACH_OBSERVER(BrowserPluginObserver, observers_, OnDestruct()); |
if (compositing_helper_) |
compositing_helper_->OnContainerDestroy(); |
MessageLoop::current()->DeleteSoon(FROM_HERE, this); |
} |
-NPObject* BrowserPlugin::scriptableObject() { |
+NPObject* BrowserPluginImpl::scriptableObject() { |
if (!bindings_.get()) |
return NULL; |
@@ -1066,19 +1029,18 @@ NPObject* BrowserPlugin::scriptableObject() { |
return browser_plugin_np_object; |
} |
-bool BrowserPlugin::supportsKeyboardFocus() const { |
+bool BrowserPluginImpl::supportsKeyboardFocus() const { |
return true; |
} |
-bool BrowserPlugin::canProcessDrag() const { |
+bool BrowserPluginImpl::canProcessDrag() const { |
return true; |
} |
-void BrowserPlugin::paint(WebCanvas* canvas, const WebRect& rect) { |
+void BrowserPluginImpl::paint(WebCanvas* canvas, const WebRect& rect) { |
if (guest_crashed_) { |
if (!sad_guest_) // Lazily initialize bitmap. |
- sad_guest_ = content::GetContentClient()->renderer()-> |
- GetSadWebViewBitmap(); |
+ sad_guest_ = GetContentClient()->renderer()->GetSadWebViewBitmap(); |
// content_shell does not have the sad plugin bitmap, so we'll paint black |
// instead to make it clear that something went wrong. |
if (sad_guest_) { |
@@ -1109,7 +1071,7 @@ void BrowserPlugin::paint(WebCanvas* canvas, const WebRect& rect) { |
canvas->drawBitmap(backing_store_->GetBitmap(), 0, 0); |
} |
-bool BrowserPlugin::InBounds(const gfx::Point& position) const { |
+bool BrowserPluginImpl::InBounds(const gfx::Point& position) const { |
// Note that even for plugins that are rotated using rotate transformations, |
// we use the the |plugin_rect_| provided by updateGeometry, which means we |
// will be off if |position| is within the plugin rect but does not fall |
@@ -1124,13 +1086,120 @@ bool BrowserPlugin::InBounds(const gfx::Point& position) const { |
return result; |
} |
-gfx::Point BrowserPlugin::ToLocalCoordinates(const gfx::Point& point) const { |
+RenderView* BrowserPluginImpl::GetRenderView() const { |
+ return render_view_.get(); |
+} |
+ |
+WebKit::WebPluginContainer* BrowserPluginImpl::GetContainer() const { |
+ return container(); |
+} |
+ |
+void BrowserPluginImpl::AddMethodBinding( |
+ BrowserPluginMethodBinding* method_binding) { |
+ bindings_->AddMethodBinding(method_binding); |
+} |
+ |
+void BrowserPluginImpl::AddPropertyBinding( |
+ BrowserPluginPropertyBinding* method_binding) { |
+ bindings_->AddPropertyBinding(method_binding); |
+} |
+ |
+void BrowserPluginImpl::TriggerEvent( |
+ const std::string& event_name, |
+ std::map<std::string, base::Value*>* props) { |
+ if (!container() || !container()->element().document().frame()) |
+ return; |
+ v8::HandleScope handle_scope; |
+ std::string json_string; |
+ if (props) { |
+ base::DictionaryValue dict; |
+ for (std::map<std::string, base::Value*>::iterator iter = props->begin(), |
+ end = props->end(); iter != end; ++iter) { |
+ dict.Set(iter->first, iter->second); |
+ } |
+ |
+ JSONStringValueSerializer serializer(&json_string); |
+ if (!serializer.Serialize(dict)) |
+ return; |
+ } |
+ |
+ WebKit::WebFrame* frame = container()->element().document().frame(); |
+ WebKit::WebDOMEvent dom_event = frame->document().createEvent("CustomEvent"); |
+ WebKit::WebDOMCustomEvent event = dom_event.to<WebKit::WebDOMCustomEvent>(); |
+ |
+ // The events triggered directly from the plugin <object> are internal events |
+ // whose implementation details can (and likely will) change over time. The |
+ // wrapper/shim (e.g. <webview> tag) should receive these events, and expose a |
+ // more appropriate (and stable) event to the consumers as part of the API. |
+ event.initCustomEvent( |
+ WebKit::WebString::fromUTF8(GetInternalEventName(event_name.c_str())), |
+ false, false, |
+ WebKit::WebSerializedScriptValue::serialize( |
+ v8::String::New(json_string.c_str(), json_string.size()))); |
+ container()->element().dispatchEvent(event); |
+} |
+ |
+void BrowserPluginImpl::UpdateDOMAttribute(const std::string& attribute_name, |
+ const std::string& attribute_value) { |
+ if (!container()) |
+ return; |
+ |
+ WebKit::WebElement element = container()->element(); |
+ WebKit::WebString web_attribute_name = |
+ WebKit::WebString::fromUTF8(attribute_name); |
+ if (!HasDOMAttribute(attribute_name) || |
+ (std::string(element.getAttribute(web_attribute_name).utf8()) != |
+ attribute_value)) { |
+ element.setAttribute(web_attribute_name, |
+ WebKit::WebString::fromUTF8(attribute_value)); |
+ } |
+} |
+void BrowserPluginImpl::RemoveDOMAttribute(const std::string& attribute_name) { |
+ if (!container()) |
+ return; |
+ |
+ container()->element().removeAttribute( |
+ WebKit::WebString::fromUTF8(attribute_name)); |
+} |
+ |
+std::string BrowserPluginImpl::GetDOMAttributeValue( |
+ const std::string& attribute_name) const { |
+ if (!container()) |
+ return ""; |
+ |
+ return container()->element().getAttribute( |
+ WebKit::WebString::fromUTF8(attribute_name)).utf8(); |
+} |
+ |
+bool BrowserPluginImpl::HasDOMAttribute( |
+ const std::string& attribute_name) const { |
+ if (!container()) |
+ return false; |
+ |
+ return container()->element().hasAttribute( |
+ WebKit::WebString::fromUTF8(attribute_name)); |
+} |
+ |
+bool BrowserPluginImpl::HasNavigated() const { |
+ return navigate_src_sent_; |
+} |
+ |
+bool BrowserPluginImpl::Send(IPC::Message* message) { |
+ IPC::Message* wrapper_msg = |
+ new BrowserPluginHostMsg_ForwardMessage( |
+ render_view_routing_id_, instance_id_, *message); |
+ delete message; |
+ return browser_plugin_manager()->Send(wrapper_msg); |
+} |
+ |
+gfx::Point BrowserPluginImpl::ToLocalCoordinates( |
+ const gfx::Point& point) const { |
if (container_) |
return container_->windowToLocalPoint(WebKit::WebPoint(point)); |
return gfx::Point(point.x() - plugin_rect_.x(), point.y() - plugin_rect_.y()); |
} |
-void BrowserPlugin::updateGeometry( |
+void BrowserPluginImpl::updateGeometry( |
const WebRect& window_rect, |
const WebRect& clip_rect, |
const WebVector<WebRect>& cut_outs_rects, |
@@ -1160,12 +1229,12 @@ void BrowserPlugin::updateGeometry( |
params)); |
} |
-void BrowserPlugin::SwapDamageBuffers() { |
+void BrowserPluginImpl::SwapDamageBuffers() { |
current_damage_buffer_.reset(pending_damage_buffer_.release()); |
resize_ack_received_ = true; |
} |
-void BrowserPlugin::PopulateResizeGuestParameters( |
+void BrowserPluginImpl::PopulateResizeGuestParameters( |
BrowserPluginHostMsg_ResizeGuest_Params* params, |
const gfx::Size& view_size) { |
params->view_size = view_size; |
@@ -1193,7 +1262,7 @@ void BrowserPlugin::PopulateResizeGuestParameters( |
params->damage_buffer_sequence_id = ++damage_buffer_sequence_id_; |
} |
-void BrowserPlugin::GetDamageBufferWithSizeParams( |
+void BrowserPluginImpl::GetDamageBufferWithSizeParams( |
BrowserPluginHostMsg_AutoSize_Params* auto_size_params, |
BrowserPluginHostMsg_ResizeGuest_Params* resize_guest_params) { |
if (auto_size_params) |
@@ -1207,7 +1276,7 @@ void BrowserPlugin::GetDamageBufferWithSizeParams( |
} |
#if defined(OS_POSIX) |
-base::SharedMemory* BrowserPlugin::CreateDamageBuffer( |
+base::SharedMemory* BrowserPluginImpl::CreateDamageBuffer( |
const size_t size, |
base::SharedMemoryHandle* damage_buffer_handle) { |
scoped_ptr<base::SharedMemory> shared_buf( |
@@ -1227,7 +1296,7 @@ base::SharedMemory* BrowserPlugin::CreateDamageBuffer( |
return NULL; |
} |
#elif defined(OS_WIN) |
-base::SharedMemory* BrowserPlugin::CreateDamageBuffer( |
+base::SharedMemory* BrowserPluginImpl::CreateDamageBuffer( |
const size_t size, |
base::SharedMemoryHandle* damage_buffer_handle) { |
scoped_ptr<base::SharedMemory> shared_buf(new base::SharedMemory()); |
@@ -1236,7 +1305,6 @@ base::SharedMemory* BrowserPlugin::CreateDamageBuffer( |
NOTREACHED() << "Buffer allocation failed"; |
return NULL; |
} |
- |
// Insert the magic word. |
*static_cast<unsigned int*>(shared_buf->memory()) = 0xdeadbeef; |
if (shared_buf->ShareToProcess(base::GetCurrentProcessHandle(), |
@@ -1247,7 +1315,7 @@ base::SharedMemory* BrowserPlugin::CreateDamageBuffer( |
} |
#endif |
-void BrowserPlugin::updateFocus(bool focused) { |
+void BrowserPluginImpl::updateFocus(bool focused) { |
if (plugin_focused_ == focused) |
return; |
@@ -1258,7 +1326,7 @@ void BrowserPlugin::updateFocus(bool focused) { |
UpdateGuestFocusState(); |
} |
-void BrowserPlugin::updateVisibility(bool visible) { |
+void BrowserPluginImpl::updateVisibility(bool visible) { |
if (visible_ == visible) |
return; |
@@ -1275,12 +1343,12 @@ void BrowserPlugin::updateVisibility(bool visible) { |
visible)); |
} |
-bool BrowserPlugin::acceptsInputEvents() { |
+bool BrowserPluginImpl::acceptsInputEvents() { |
return true; |
} |
-bool BrowserPlugin::handleInputEvent(const WebKit::WebInputEvent& event, |
- WebKit::WebCursorInfo& cursor_info) { |
+bool BrowserPluginImpl::handleInputEvent(const WebKit::WebInputEvent& event, |
+ WebKit::WebCursorInfo& cursor_info) { |
if (guest_crashed_ || !navigate_src_sent_ || |
event.type == WebKit::WebInputEvent::ContextMenu) |
return false; |
@@ -1293,42 +1361,42 @@ bool BrowserPlugin::handleInputEvent(const WebKit::WebInputEvent& event, |
return true; |
} |
-bool BrowserPlugin::handleDragStatusUpdate(WebKit::WebDragStatus drag_status, |
- const WebKit::WebDragData& drag_data, |
- WebKit::WebDragOperationsMask mask, |
- const WebKit::WebPoint& position, |
- const WebKit::WebPoint& screen) { |
+bool BrowserPluginImpl::handleDragStatusUpdate( |
+ WebKit::WebDragStatus drag_status, |
+ const WebKit::WebDragData& drag_data, |
+ WebKit::WebDragOperationsMask mask, |
+ const WebKit::WebPoint& position, |
+ const WebKit::WebPoint& screen) { |
if (guest_crashed_ || !navigate_src_sent_) |
return false; |
- browser_plugin_manager()->Send( |
- new BrowserPluginHostMsg_DragStatusUpdate( |
- render_view_routing_id_, |
- instance_id_, |
- drag_status, |
- WebDropData(drag_data), |
- mask, |
- position)); |
+ browser_plugin_manager()->Send(new BrowserPluginHostMsg_DragStatusUpdate( |
+ render_view_routing_id_, |
+ instance_id_, |
+ drag_status, |
+ WebDropData(drag_data), |
+ mask, |
+ position)); |
return false; |
} |
-void BrowserPlugin::didReceiveResponse( |
+void BrowserPluginImpl::didReceiveResponse( |
const WebKit::WebURLResponse& response) { |
} |
-void BrowserPlugin::didReceiveData(const char* data, int data_length) { |
+void BrowserPluginImpl::didReceiveData(const char* data, int data_length) { |
} |
-void BrowserPlugin::didFinishLoading() { |
+void BrowserPluginImpl::didFinishLoading() { |
} |
-void BrowserPlugin::didFailLoading(const WebKit::WebURLError& error) { |
+void BrowserPluginImpl::didFailLoading(const WebKit::WebURLError& error) { |
} |
-void BrowserPlugin::didFinishLoadingFrameRequest(const WebKit::WebURL& url, |
- void* notify_data) { |
+void BrowserPluginImpl::didFinishLoadingFrameRequest(const WebKit::WebURL& url, |
+ void* notify_data) { |
} |
-void BrowserPlugin::didFailLoadingFrameRequest( |
+void BrowserPluginImpl::didFailLoadingFrameRequest( |
const WebKit::WebURL& url, |
void* notify_data, |
const WebKit::WebURLError& error) { |