| 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 47de906da2c4f3b73d9ab92bed608d4aa995d4c8..1f82b5ae67f51aee03bbcda84673471f6d3f7b2f 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)
|
| @@ -100,9 +101,10 @@ BrowserPlugin::BrowserPlugin(
|
| nav_entry_count_(0),
|
| compositing_enabled_(false) {
|
| bindings_.reset(new BrowserPluginBindings(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.
|
| @@ -114,11 +116,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)
|
| @@ -139,98 +150,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.
|
| @@ -239,7 +209,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.
|
| @@ -248,11 +218,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(
|
| @@ -261,7 +231,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;
|
| @@ -297,13 +267,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.
|
| @@ -313,10 +283,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;
|
| @@ -334,7 +304,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;
|
| @@ -350,19 +321,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);
|
| @@ -387,16 +358,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);
|
|
|
| @@ -406,13 +377,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.
|
| @@ -428,7 +414,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);
|
|
|
| @@ -443,22 +429,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);
|
| @@ -466,7 +452,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
|
| @@ -487,10 +473,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());
|
| @@ -498,9 +484,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);
|
| @@ -508,15 +494,16 @@ 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::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 :
|
| @@ -524,11 +511,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::OnUpdateRect(
|
| +void BrowserPluginImpl::OnUpdateRect(
|
| int instance_id,
|
| const BrowserPluginMsg_UpdateRect_Params& params) {
|
| bool use_new_damage_buffer = !backing_store_;
|
| @@ -605,7 +593,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));
|
| }
|
| @@ -656,18 +644,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*>(
|
| @@ -678,16 +666,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;
|
| @@ -719,13 +707,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);
|
| @@ -735,47 +724,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::Back() {
|
| +void BrowserPluginImpl::Back() {
|
| if (!navigate_src_sent_)
|
| return;
|
| browser_plugin_manager()->Send(
|
| @@ -783,7 +738,7 @@ void BrowserPlugin::Back() {
|
| instance_id_, -1));
|
| }
|
|
|
| -void BrowserPlugin::Forward() {
|
| +void BrowserPluginImpl::Forward() {
|
| if (!navigate_src_sent_)
|
| return;
|
| browser_plugin_manager()->Send(
|
| @@ -791,7 +746,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(
|
| @@ -800,7 +755,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(
|
| @@ -808,7 +763,7 @@ void BrowserPlugin::TerminateGuest() {
|
| instance_id_));
|
| }
|
|
|
| -void BrowserPlugin::Stop() {
|
| +void BrowserPluginImpl::Stop() {
|
| if (!navigate_src_sent_)
|
| return;
|
| browser_plugin_manager()->Send(
|
| @@ -816,7 +771,7 @@ void BrowserPlugin::Stop() {
|
| instance_id_));
|
| }
|
|
|
| -void BrowserPlugin::Reload() {
|
| +void BrowserPluginImpl::Reload() {
|
| if (!navigate_src_sent_)
|
| return;
|
| browser_plugin_manager()->Send(
|
| @@ -824,7 +779,7 @@ void BrowserPlugin::Reload() {
|
| instance_id_));
|
| }
|
|
|
| -void BrowserPlugin::UpdateGuestFocusState() {
|
| +void BrowserPluginImpl::UpdateGuestFocusState() {
|
| if (!navigate_src_sent_)
|
| return;
|
| bool should_be_focused = ShouldGuestBeFocused();
|
| @@ -834,25 +789,25 @@ 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_;
|
| }
|
|
|
| -bool BrowserPlugin::initialize(WebPluginContainer* container) {
|
| +bool BrowserPluginImpl::initialize(WebPluginContainer* container) {
|
| container_ = container;
|
| container_->setWantsWheelEvents(true);
|
| ParseAttributes();
|
| return true;
|
| }
|
|
|
| -void BrowserPlugin::EnableCompositing(bool enable) {
|
| +void BrowserPluginImpl::EnableCompositing(bool enable) {
|
| if (compositing_enabled_ == enable)
|
| return;
|
|
|
| @@ -886,35 +841,41 @@ 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() {
|
| NPObject* browser_plugin_np_object(bindings_->np_object());
|
| // The object is expected to be retained before it is returned.
|
| WebKit::WebBindings::retainObject(browser_plugin_np_object);
|
| 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_) {
|
| @@ -945,7 +906,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
|
| @@ -960,13 +921,120 @@ bool BrowserPlugin::InBounds(const gfx::Point& position) const {
|
| return result;
|
| }
|
|
|
| -gfx::Point BrowserPlugin::ToLocalCoordinates(const gfx::Point& point) const {
|
| +void BrowserPluginImpl::AddMethodBinding(
|
| + BrowserPluginMethodBinding* method_binding) {
|
| + bindings_->AddMethodBinding(method_binding);
|
| +}
|
| +
|
| +void BrowserPluginImpl::AddPropertyBinding(
|
| + BrowserPluginPropertyBinding* method_binding) {
|
| + bindings_->AddPropertyBinding(method_binding);
|
| +}
|
| +
|
| +RenderView* BrowserPluginImpl::GetRenderView() const {
|
| + return render_view_.get();
|
| +}
|
| +
|
| +WebKit::WebPluginContainer* BrowserPluginImpl::GetContainer() const {
|
| + return container();
|
| +}
|
| +
|
| +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,
|
| @@ -996,12 +1064,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;
|
| @@ -1029,7 +1097,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)
|
| @@ -1043,7 +1111,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(
|
| @@ -1063,7 +1131,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());
|
| @@ -1072,7 +1140,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(),
|
| @@ -1083,7 +1150,7 @@ base::SharedMemory* BrowserPlugin::CreateDamageBuffer(
|
| }
|
| #endif
|
|
|
| -void BrowserPlugin::updateFocus(bool focused) {
|
| +void BrowserPluginImpl::updateFocus(bool focused) {
|
| if (plugin_focused_ == focused)
|
| return;
|
|
|
| @@ -1094,7 +1161,7 @@ void BrowserPlugin::updateFocus(bool focused) {
|
| UpdateGuestFocusState();
|
| }
|
|
|
| -void BrowserPlugin::updateVisibility(bool visible) {
|
| +void BrowserPluginImpl::updateVisibility(bool visible) {
|
| if (visible_ == visible)
|
| return;
|
|
|
| @@ -1111,12 +1178,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;
|
| @@ -1129,42 +1196,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) {
|
|
|