OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "components/plugins/renderer/plugin_placeholder.h" | 5 #include "components/plugins/renderer/plugin_placeholder.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
9 #include "base/json/string_escape.h" | 9 #include "base/json/string_escape.h" |
10 #include "base/strings/string_piece.h" | 10 #include "base/strings/string_piece.h" |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
100 plugin_->RestoreTitleText(); | 100 plugin_->RestoreTitleText(); |
101 container->invalidate(); | 101 container->invalidate(); |
102 container->reportGeometry(); | 102 container->reportGeometry(); |
103 plugin_->ReplayReceivedData(new_plugin); | 103 plugin_->ReplayReceivedData(new_plugin); |
104 plugin_->destroy(); | 104 plugin_->destroy(); |
105 plugin_ = NULL; | 105 plugin_ = NULL; |
106 } | 106 } |
107 | 107 |
108 void PluginPlaceholder::HidePlugin() { | 108 void PluginPlaceholder::HidePlugin() { |
109 hidden_ = true; | 109 hidden_ = true; |
| 110 if (!plugin_) |
| 111 return; |
110 WebPluginContainer* container = plugin_->container(); | 112 WebPluginContainer* container = plugin_->container(); |
111 WebElement element = container->element(); | 113 WebElement element = container->element(); |
112 element.setAttribute("style", "display: none;"); | 114 element.setAttribute("style", "display: none;"); |
113 // If we have a width and height, search for a parent (often <div>) with the | 115 // If we have a width and height, search for a parent (often <div>) with the |
114 // same dimensions. If we find such a parent, hide that as well. | 116 // same dimensions. If we find such a parent, hide that as well. |
115 // This makes much more uncovered page content usable (including clickable) | 117 // This makes much more uncovered page content usable (including clickable) |
116 // as opposed to merely visible. | 118 // as opposed to merely visible. |
117 // TODO(cevans) -- it's a foul heurisitc but we're going to tolerate it for | 119 // TODO(cevans) -- it's a foul heurisitc but we're going to tolerate it for |
118 // now for these reasons: | 120 // now for these reasons: |
119 // 1) Makes the user experience better. | 121 // 1) Makes the user experience better. |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
151 } | 153 } |
152 } | 154 } |
153 | 155 |
154 void PluginPlaceholder::SetMessage(const base::string16& message) { | 156 void PluginPlaceholder::SetMessage(const base::string16& message) { |
155 message_ = message; | 157 message_ = message; |
156 if (finished_loading_) | 158 if (finished_loading_) |
157 UpdateMessage(); | 159 UpdateMessage(); |
158 } | 160 } |
159 | 161 |
160 void PluginPlaceholder::UpdateMessage() { | 162 void PluginPlaceholder::UpdateMessage() { |
| 163 if (!plugin_) |
| 164 return; |
161 std::string script = | 165 std::string script = |
162 "window.setMessage(" + base::GetQuotedJSONString(message_) + ")"; | 166 "window.setMessage(" + base::GetQuotedJSONString(message_) + ")"; |
163 plugin_->web_view()->mainFrame()->executeScript( | 167 plugin_->web_view()->mainFrame()->executeScript( |
164 WebScriptSource(base::ASCIIToUTF16(script))); | 168 WebScriptSource(base::ASCIIToUTF16(script))); |
165 } | 169 } |
166 | 170 |
167 void PluginPlaceholder::ShowContextMenu(const WebMouseEvent& event) { | 171 void PluginPlaceholder::ShowContextMenu(const WebMouseEvent& event) { |
168 // Does nothing by default. Will be overridden if a specific browser wants | 172 // Does nothing by default. Will be overridden if a specific browser wants |
169 // a context menu. | 173 // a context menu. |
170 return; | 174 return; |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
237 identifier_ = identifier; | 241 identifier_ = identifier; |
238 } | 242 } |
239 | 243 |
240 blink::WebFrame* PluginPlaceholder::GetFrame() { return frame_; } | 244 blink::WebFrame* PluginPlaceholder::GetFrame() { return frame_; } |
241 | 245 |
242 const blink::WebPluginParams& PluginPlaceholder::GetPluginParams() const { | 246 const blink::WebPluginParams& PluginPlaceholder::GetPluginParams() const { |
243 return plugin_params_; | 247 return plugin_params_; |
244 } | 248 } |
245 | 249 |
246 } // namespace plugins | 250 } // namespace plugins |
OLD | NEW |