Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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 "chrome/renderer/render_view.h" | 5 #include "chrome/renderer/render_view.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <string> | 8 #include <string> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| (...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 172 // Typically, we capture the page data once the page is loaded. | 172 // Typically, we capture the page data once the page is loaded. |
| 173 // Sometimes, the page never finishes to load, preventing the page capture | 173 // Sometimes, the page never finishes to load, preventing the page capture |
| 174 // To workaround this problem, we always perform a capture after the following | 174 // To workaround this problem, we always perform a capture after the following |
| 175 // delay. | 175 // delay. |
| 176 static const int kDelayForForcedCaptureMs = 6000; | 176 static const int kDelayForForcedCaptureMs = 6000; |
| 177 | 177 |
| 178 // The default value for RenderView.delay_seconds_for_form_state_sync_, see | 178 // The default value for RenderView.delay_seconds_for_form_state_sync_, see |
| 179 // that variable for more. | 179 // that variable for more. |
| 180 const int kDefaultDelaySecondsForFormStateSync = 5; | 180 const int kDefaultDelaySecondsForFormStateSync = 5; |
| 181 | 181 |
| 182 // The next available page ID to use. This ensures that the page IDs are | |
| 183 // globally unique in the renderer. | |
| 184 static int32 next_page_id_ = 1; | |
| 185 | |
| 186 // The maximum number of popups that can be spawned from one page. | 182 // The maximum number of popups that can be spawned from one page. |
| 187 static const int kMaximumNumberOfUnacknowledgedPopups = 25; | 183 static const int kMaximumNumberOfUnacknowledgedPopups = 25; |
| 188 | 184 |
| 189 static const char* const kUnreachableWebDataURL = | 185 static const char* const kUnreachableWebDataURL = |
| 190 "chrome://chromewebdata/"; | 186 "chrome://chromewebdata/"; |
| 191 | 187 |
| 192 static const char* const kBackForwardNavigationScheme = "history"; | 188 static const char* const kBackForwardNavigationScheme = "history"; |
| 193 | 189 |
| 194 static void GetRedirectChain(WebDataSource* ds, std::vector<GURL>* result) { | 190 static void GetRedirectChain(WebDataSource* ds, std::vector<GURL>* result) { |
| 195 WebVector<WebURL> urls; | 191 WebVector<WebURL> urls; |
| 196 ds->redirectChain(urls); | 192 ds->redirectChain(urls); |
| 197 result->reserve(urls.size()); | 193 result->reserve(urls.size()); |
| 198 for (size_t i = 0; i < urls.size(); ++i) | 194 for (size_t i = 0; i < urls.size(); ++i) |
| 199 result->push_back(urls[i]); | 195 result->push_back(urls[i]); |
| 200 } | 196 } |
| 201 | 197 |
| 202 /////////////////////////////////////////////////////////////////////////////// | 198 /////////////////////////////////////////////////////////////////////////////// |
| 203 | 199 |
| 200 int32 RenderView::next_page_id_ = 1; | |
| 201 | |
| 204 RenderView::RenderView(RenderThreadBase* render_thread, | 202 RenderView::RenderView(RenderThreadBase* render_thread, |
| 205 const WebPreferences& webkit_preferences) | 203 const WebPreferences& webkit_preferences) |
| 206 : RenderWidget(render_thread, true), | 204 : RenderWidget(render_thread, true), |
| 207 enabled_bindings_(0), | 205 enabled_bindings_(0), |
| 208 target_url_status_(TARGET_NONE), | 206 target_url_status_(TARGET_NONE), |
| 209 is_loading_(false), | 207 is_loading_(false), |
| 210 navigation_gesture_(NavigationGestureUnknown), | 208 navigation_gesture_(NavigationGestureUnknown), |
| 211 page_id_(-1), | 209 page_id_(-1), |
| 212 last_page_id_sent_to_browser_(-1), | 210 last_page_id_sent_to_browser_(-1), |
| 213 last_indexed_page_id_(-1), | 211 last_indexed_page_id_(-1), |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 228 send_preferred_width_changes_(false), | 226 send_preferred_width_changes_(false), |
| 229 determine_page_text_after_loading_stops_(false), | 227 determine_page_text_after_loading_stops_(false), |
| 230 view_type_(ViewType::INVALID), | 228 view_type_(ViewType::INVALID), |
| 231 browser_window_id_(-1), | 229 browser_window_id_(-1), |
| 232 last_top_level_navigation_page_id_(-1), | 230 last_top_level_navigation_page_id_(-1), |
| 233 #if defined(OS_MACOSX) | 231 #if defined(OS_MACOSX) |
| 234 has_document_tag_(false), | 232 has_document_tag_(false), |
| 235 #endif | 233 #endif |
| 236 document_tag_(0), | 234 document_tag_(0), |
| 237 webkit_preferences_(webkit_preferences) { | 235 webkit_preferences_(webkit_preferences) { |
| 238 Singleton<RenderViewSet>()->render_view_set_.insert(this); | |
| 239 } | 236 } |
| 240 | 237 |
| 241 RenderView::~RenderView() { | 238 RenderView::~RenderView() { |
| 242 Singleton<RenderViewSet>()->render_view_set_.erase(this); | |
| 243 if (decrement_shared_popup_at_destruction_) | 239 if (decrement_shared_popup_at_destruction_) |
| 244 shared_popup_counter_->data--; | 240 shared_popup_counter_->data--; |
| 245 | 241 |
| 246 // Dispose of un-disposed image fetchers. | 242 // Dispose of un-disposed image fetchers. |
| 247 for (ImageResourceFetcherSet::iterator i = image_fetchers_.begin(); | 243 for (ImageResourceFetcherSet::iterator i = image_fetchers_.begin(); |
| 248 i != image_fetchers_.end(); ++i) { | 244 i != image_fetchers_.end(); ++i) { |
| 249 delete *i; | 245 delete *i; |
| 250 } | 246 } |
| 251 | 247 |
| 252 // If file chooser is still waiting for answer, dispatch empty answer. | 248 // If file chooser is still waiting for answer, dispatch empty answer. |
| 253 if (file_chooser_completion_) | 249 if (file_chooser_completion_) |
| 254 file_chooser_completion_->didChooseFile(WebVector<WebString>()); | 250 file_chooser_completion_->didChooseFile(WebVector<WebString>()); |
| 255 | 251 |
| 256 #if defined(OS_MACOSX) | 252 #if defined(OS_MACOSX) |
| 257 // Tell the spellchecker that the document is closed. | 253 // Tell the spellchecker that the document is closed. |
| 258 if (has_document_tag_) | 254 if (has_document_tag_) |
| 259 Send(new ViewHostMsg_DocumentWithTagClosed(routing_id_, document_tag_)); | 255 Send(new ViewHostMsg_DocumentWithTagClosed(routing_id_, document_tag_)); |
| 260 #endif | 256 #endif |
| 261 | 257 |
| 262 render_thread_->RemoveFilter(audio_message_filter_); | 258 render_thread_->RemoveFilter(audio_message_filter_); |
| 263 render_thread_->RemoveFilter(notification_provider_.get()); | 259 render_thread_->RemoveFilter(notification_provider_.get()); |
| 260 | |
| 261 #ifndef NDEBUG | |
| 262 // Make sure we are no longer referenced by the ViewMap. | |
| 263 ViewMap* views = Singleton<ViewMap>::get(); | |
| 264 for (ViewMap::iterator it = views->begin(); it != views->end(); ++it) | |
| 265 DCHECK_NE(this, it->second) << "Failed to call Close?"; | |
| 266 #endif | |
| 267 } | |
| 268 | |
| 269 /*static*/ | |
| 270 void RenderView::ForEach(RenderViewVisitor* visitor) { | |
| 271 ViewMap* views = Singleton<ViewMap>::get(); | |
| 272 for (ViewMap::iterator it = views->begin(); it != views->end(); ++it) | |
| 273 visitor->Visit(it->second); | |
|
Matt Perry
2009/10/09 00:25:14
I think you want to break if this returns false?
darin (slow to review)
2009/10/09 03:52:30
Yes, thanks for catching that!
| |
| 274 } | |
| 275 | |
| 276 /*static*/ | |
| 277 RenderView* RenderView::FromWebView(WebView* webview) { | |
| 278 ViewMap* views = Singleton<ViewMap>::get(); | |
| 279 ViewMap::iterator it = views->find(webview); | |
| 280 return it == views->end() ? NULL : it->second; | |
| 264 } | 281 } |
| 265 | 282 |
| 266 /*static*/ | 283 /*static*/ |
| 267 RenderView* RenderView::Create( | 284 RenderView* RenderView::Create( |
| 268 RenderThreadBase* render_thread, | 285 RenderThreadBase* render_thread, |
| 269 gfx::NativeViewId parent_hwnd, | 286 gfx::NativeViewId parent_hwnd, |
| 270 int32 opener_id, | 287 int32 opener_id, |
| 271 const RendererPreferences& renderer_prefs, | 288 const RendererPreferences& renderer_prefs, |
| 272 const WebPreferences& webkit_prefs, | 289 const WebPreferences& webkit_prefs, |
| 273 SharedRenderViewCounter* counter, | 290 SharedRenderViewCounter* counter, |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 317 } else { | 334 } else { |
| 318 shared_popup_counter_ = new SharedRenderViewCounter(0); | 335 shared_popup_counter_ = new SharedRenderViewCounter(0); |
| 319 decrement_shared_popup_at_destruction_ = false; | 336 decrement_shared_popup_at_destruction_ = false; |
| 320 } | 337 } |
| 321 | 338 |
| 322 devtools_agent_.reset(new DevToolsAgent(routing_id, this)); | 339 devtools_agent_.reset(new DevToolsAgent(routing_id, this)); |
| 323 | 340 |
| 324 notification_provider_ = new NotificationProvider(this); | 341 notification_provider_ = new NotificationProvider(this); |
| 325 | 342 |
| 326 webwidget_ = WebView::Create(this); | 343 webwidget_ = WebView::Create(this); |
| 344 Singleton<ViewMap>::get()->insert(std::make_pair(webview(), this)); | |
| 327 webkit_preferences_.Apply(webview()); | 345 webkit_preferences_.Apply(webview()); |
| 328 webview()->initializeMainFrame(this); | 346 webview()->initializeMainFrame(this); |
| 329 | 347 |
| 330 OnSetRendererPrefs(renderer_prefs); | 348 OnSetRendererPrefs(renderer_prefs); |
| 331 | 349 |
| 332 routing_id_ = routing_id; | 350 routing_id_ = routing_id; |
| 333 render_thread_->AddRoute(routing_id_, this); | 351 render_thread_->AddRoute(routing_id_, this); |
| 334 // Take a reference on behalf of the RenderThread. This will be balanced | 352 // Take a reference on behalf of the RenderThread. This will be balanced |
| 335 // when we receive ViewMsg_Close. | 353 // when we receive ViewMsg_Close. |
| 336 AddRef(); | 354 AddRef(); |
| (...skipping 3272 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3609 main_frame->executeScriptInIsolatedWorld( | 3627 main_frame->executeScriptInIsolatedWorld( |
| 3610 UserScriptSlave::GetIsolatedWorldId(extension_id), | 3628 UserScriptSlave::GetIsolatedWorldId(extension_id), |
| 3611 &sources.front(), sources.size(), EXTENSION_GROUP_CONTENT_SCRIPTS); | 3629 &sources.front(), sources.size(), EXTENSION_GROUP_CONTENT_SCRIPTS); |
| 3612 } else { | 3630 } else { |
| 3613 main_frame->insertStyleText(WebString::fromUTF8(code_string), WebString()); | 3631 main_frame->insertStyleText(WebString::fromUTF8(code_string), WebString()); |
| 3614 } | 3632 } |
| 3615 | 3633 |
| 3616 Send(new ViewMsg_ExecuteCodeFinished(routing_id_, request_id, true)); | 3634 Send(new ViewMsg_ExecuteCodeFinished(routing_id_, request_id, true)); |
| 3617 } | 3635 } |
| 3618 | 3636 |
| 3637 void RenderView::Close() { | |
| 3638 // We need to grab a pointer to the doomed WebView before we destroy it. | |
| 3639 WebView* doomed = webview(); | |
| 3640 RenderWidget::Close(); | |
| 3641 Singleton<ViewMap>::get()->erase(doomed); | |
| 3642 } | |
| 3643 | |
| 3619 void RenderView::DidHandleKeyEvent() { | 3644 void RenderView::DidHandleKeyEvent() { |
| 3620 edit_commands_.clear(); | 3645 edit_commands_.clear(); |
| 3621 } | 3646 } |
| 3622 | 3647 |
| 3623 void RenderView::EnsureDocumentTag() { | 3648 void RenderView::EnsureDocumentTag() { |
| 3624 // TODO(darin): There's actually no reason for this to be here. We should | 3649 // TODO(darin): There's actually no reason for this to be here. We should |
| 3625 // have the browser side manage the document tag. | 3650 // have the browser side manage the document tag. |
| 3626 #if defined(OS_MACOSX) | 3651 #if defined(OS_MACOSX) |
| 3627 if (!has_document_tag_) { | 3652 if (!has_document_tag_) { |
| 3628 // Make the call to get the tag. | 3653 // Make the call to get the tag. |
| 3629 Send(new ViewHostMsg_GetDocumentTag(routing_id_, &document_tag_)); | 3654 Send(new ViewHostMsg_GetDocumentTag(routing_id_, &document_tag_)); |
| 3630 has_document_tag_ = true; | 3655 has_document_tag_ = true; |
| 3631 } | 3656 } |
| 3632 #endif | 3657 #endif |
| 3633 } | 3658 } |
| 3634 | 3659 |
| 3635 bool RenderView::SendAndRunNestedMessageLoop(IPC::SyncMessage* message) { | 3660 bool RenderView::SendAndRunNestedMessageLoop(IPC::SyncMessage* message) { |
| 3636 PluginChannelHost::Broadcast( | 3661 PluginChannelHost::Broadcast( |
| 3637 new PluginMsg_SignalModalDialogEvent(host_window_)); | 3662 new PluginMsg_SignalModalDialogEvent(host_window_)); |
| 3638 | 3663 |
| 3639 message->EnableMessagePumping(); // Runs a nested message loop. | 3664 message->EnableMessagePumping(); // Runs a nested message loop. |
| 3640 bool rv = Send(message); | 3665 bool rv = Send(message); |
| 3641 | 3666 |
| 3642 PluginChannelHost::Broadcast( | 3667 PluginChannelHost::Broadcast( |
| 3643 new PluginMsg_ResetModalDialogEvent(host_window_)); | 3668 new PluginMsg_ResetModalDialogEvent(host_window_)); |
| 3644 | 3669 |
| 3645 return rv; | 3670 return rv; |
| 3646 } | 3671 } |
| OLD | NEW |