| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "content/shell/shell.h" | 5 #include "content/shell/shell.h" |
| 6 | 6 |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/message_loop.h" | 8 #include "base/message_loop.h" |
| 9 #include "base/path_service.h" | 9 #include "base/path_service.h" |
| 10 #include "base/string_util.h" | 10 #include "base/string_util.h" |
| 11 #include "content/browser/renderer_host/render_view_host_impl.h" | 11 #include "content/public/browser/navigation_controller.h" |
| 12 #include "content/browser/tab_contents/navigation_controller_impl.h" | 12 #include "content/public/browser/render_view_host.h" |
| 13 #include "content/browser/tab_contents/tab_contents.h" | 13 #include "content/public/browser/web_contents.h" |
| 14 #include "content/shell/shell_messages.h" | 14 #include "content/shell/shell_messages.h" |
| 15 #include "content/shell/shell_switches.h" | 15 #include "content/shell/shell_switches.h" |
| 16 #include "ui/gfx/size.h" | 16 #include "ui/gfx/size.h" |
| 17 | 17 |
| 18 // Content area size for newly created windows. | 18 // Content area size for newly created windows. |
| 19 static const int kTestWindowWidth = 800; | 19 static const int kTestWindowWidth = 800; |
| 20 static const int kTestWindowHeight = 600; | 20 static const int kTestWindowHeight = 600; |
| 21 | 21 |
| 22 namespace content { | 22 namespace content { |
| 23 | 23 |
| 24 std::vector<Shell*> Shell::windows_; | 24 std::vector<Shell*> Shell::windows_; |
| 25 | 25 |
| 26 Shell::Shell(TabContents* tab_contents) | 26 Shell::Shell(WebContents* web_contents) |
| 27 : WebContentsObserver(tab_contents), | 27 : WebContentsObserver(web_contents), |
| 28 wait_until_done_(false), | 28 wait_until_done_(false), |
| 29 window_(NULL), | 29 window_(NULL), |
| 30 url_edit_view_(NULL) | 30 url_edit_view_(NULL) |
| 31 #if defined(OS_WIN) | 31 #if defined(OS_WIN) |
| 32 , default_edit_wnd_proc_(0) | 32 , default_edit_wnd_proc_(0) |
| 33 #endif | 33 #endif |
| 34 { | 34 { |
| 35 windows_.push_back(this); | 35 windows_.push_back(this); |
| 36 } | 36 } |
| 37 | 37 |
| 38 Shell::~Shell() { | 38 Shell::~Shell() { |
| 39 PlatformCleanUp(); | 39 PlatformCleanUp(); |
| 40 | 40 |
| 41 for (size_t i = 0; i < windows_.size(); ++i) { | 41 for (size_t i = 0; i < windows_.size(); ++i) { |
| 42 if (windows_[i] == this) { | 42 if (windows_[i] == this) { |
| 43 windows_.erase(windows_.begin() + i); | 43 windows_.erase(windows_.begin() + i); |
| 44 break; | 44 break; |
| 45 } | 45 } |
| 46 } | 46 } |
| 47 } | 47 } |
| 48 | 48 |
| 49 Shell* Shell::CreateShell(TabContents* tab_contents) { | 49 Shell* Shell::CreateShell(WebContents* web_contents) { |
| 50 Shell* shell = new Shell(tab_contents); | 50 Shell* shell = new Shell(web_contents); |
| 51 shell->PlatformCreateWindow(kTestWindowWidth, kTestWindowHeight); | 51 shell->PlatformCreateWindow(kTestWindowWidth, kTestWindowHeight); |
| 52 | 52 |
| 53 shell->tab_contents_.reset(tab_contents); | 53 shell->web_contents_.reset(web_contents); |
| 54 tab_contents->SetDelegate(shell); | 54 web_contents->SetDelegate(shell); |
| 55 | 55 |
| 56 shell->PlatformSetContents(); | 56 shell->PlatformSetContents(); |
| 57 | 57 |
| 58 shell->PlatformResizeSubViews(); | 58 shell->PlatformResizeSubViews(); |
| 59 return shell; | 59 return shell; |
| 60 } | 60 } |
| 61 | 61 |
| 62 Shell* Shell::FromRenderViewHost(RenderViewHost* rvh) { | 62 Shell* Shell::FromRenderViewHost(RenderViewHost* rvh) { |
| 63 for (size_t i = 0; i < windows_.size(); ++i) { | 63 for (size_t i = 0; i < windows_.size(); ++i) { |
| 64 if (windows_[i]->tab_contents() && | 64 if (windows_[i]->web_contents() && |
| 65 windows_[i]->tab_contents()->GetRenderViewHost() == rvh) { | 65 windows_[i]->web_contents()->GetRenderViewHost() == rvh) { |
| 66 return windows_[i]; | 66 return windows_[i]; |
| 67 } | 67 } |
| 68 } | 68 } |
| 69 return NULL; | 69 return NULL; |
| 70 } | 70 } |
| 71 | 71 |
| 72 Shell* Shell::CreateNewWindow(content::BrowserContext* browser_context, | 72 Shell* Shell::CreateNewWindow(content::BrowserContext* browser_context, |
| 73 const GURL& url, | 73 const GURL& url, |
| 74 SiteInstance* site_instance, | 74 SiteInstance* site_instance, |
| 75 int routing_id, | 75 int routing_id, |
| 76 TabContents* base_tab_contents) { | 76 WebContents* base_web_contents) { |
| 77 TabContents* tab_contents = new TabContents( | 77 WebContents* web_contents = WebContents::Create( |
| 78 browser_context, | 78 browser_context, |
| 79 site_instance, | 79 site_instance, |
| 80 routing_id, | 80 routing_id, |
| 81 base_tab_contents, | 81 base_web_contents, |
| 82 NULL); | 82 NULL); |
| 83 Shell* shell = CreateShell(tab_contents); | 83 Shell* shell = CreateShell(web_contents); |
| 84 if (!url.is_empty()) | 84 if (!url.is_empty()) |
| 85 shell->LoadURL(url); | 85 shell->LoadURL(url); |
| 86 return shell; | 86 return shell; |
| 87 } | 87 } |
| 88 | 88 |
| 89 void Shell::LoadURL(const GURL& url) { | 89 void Shell::LoadURL(const GURL& url) { |
| 90 tab_contents_->GetController().LoadURL( | 90 web_contents_->GetController().LoadURL( |
| 91 url, | 91 url, |
| 92 content::Referrer(), | 92 content::Referrer(), |
| 93 content::PAGE_TRANSITION_TYPED, | 93 content::PAGE_TRANSITION_TYPED, |
| 94 std::string()); | 94 std::string()); |
| 95 tab_contents_->Focus(); | 95 web_contents_->Focus(); |
| 96 } | 96 } |
| 97 | 97 |
| 98 void Shell::GoBackOrForward(int offset) { | 98 void Shell::GoBackOrForward(int offset) { |
| 99 tab_contents_->GetController().GoToOffset(offset); | 99 web_contents_->GetController().GoToOffset(offset); |
| 100 tab_contents_->Focus(); | 100 web_contents_->Focus(); |
| 101 } | 101 } |
| 102 | 102 |
| 103 void Shell::Reload() { | 103 void Shell::Reload() { |
| 104 tab_contents_->GetController().Reload(false); | 104 web_contents_->GetController().Reload(false); |
| 105 tab_contents_->Focus(); | 105 web_contents_->Focus(); |
| 106 } | 106 } |
| 107 | 107 |
| 108 void Shell::Stop() { | 108 void Shell::Stop() { |
| 109 tab_contents_->Stop(); | 109 web_contents_->Stop(); |
| 110 tab_contents_->Focus(); | 110 web_contents_->Focus(); |
| 111 } | 111 } |
| 112 | 112 |
| 113 void Shell::UpdateNavigationControls() { | 113 void Shell::UpdateNavigationControls() { |
| 114 int current_index = tab_contents_->GetController().GetCurrentEntryIndex(); | 114 int current_index = web_contents_->GetController().GetCurrentEntryIndex(); |
| 115 int max_index = tab_contents_->GetController().GetEntryCount() - 1; | 115 int max_index = web_contents_->GetController().GetEntryCount() - 1; |
| 116 | 116 |
| 117 PlatformEnableUIControl(BACK_BUTTON, current_index > 0); | 117 PlatformEnableUIControl(BACK_BUTTON, current_index > 0); |
| 118 PlatformEnableUIControl(FORWARD_BUTTON, current_index < max_index); | 118 PlatformEnableUIControl(FORWARD_BUTTON, current_index < max_index); |
| 119 PlatformEnableUIControl(STOP_BUTTON, tab_contents_->IsLoading()); | 119 PlatformEnableUIControl(STOP_BUTTON, web_contents_->IsLoading()); |
| 120 } | 120 } |
| 121 | 121 |
| 122 gfx::NativeView Shell::GetContentView() { | 122 gfx::NativeView Shell::GetContentView() { |
| 123 if (!tab_contents_.get()) | 123 if (!web_contents_.get()) |
| 124 return NULL; | 124 return NULL; |
| 125 return tab_contents_->GetNativeView(); | 125 return web_contents_->GetNativeView(); |
| 126 } | 126 } |
| 127 | 127 |
| 128 void Shell::LoadingStateChanged(WebContents* source) { | 128 void Shell::LoadingStateChanged(WebContents* source) { |
| 129 UpdateNavigationControls(); | 129 UpdateNavigationControls(); |
| 130 PlatformSetIsLoading(source->IsLoading()); | 130 PlatformSetIsLoading(source->IsLoading()); |
| 131 } | 131 } |
| 132 | 132 |
| 133 void Shell::WebContentsCreated(WebContents* source_contents, | 133 void Shell::WebContentsCreated(WebContents* source_contents, |
| 134 int64 source_frame_id, | 134 int64 source_frame_id, |
| 135 const GURL& target_url, | 135 const GURL& target_url, |
| 136 WebContents* new_contents) { | 136 WebContents* new_contents) { |
| 137 CreateShell(static_cast<TabContents*>(new_contents)); | 137 CreateShell(new_contents); |
| 138 } | 138 } |
| 139 | 139 |
| 140 void Shell::DidNavigateMainFramePostCommit(WebContents* tab) { | 140 void Shell::DidNavigateMainFramePostCommit(WebContents* tab) { |
| 141 PlatformSetAddressBarURL(tab->GetURL()); | 141 PlatformSetAddressBarURL(tab->GetURL()); |
| 142 } | 142 } |
| 143 | 143 |
| 144 void Shell::DidFinishLoad(int64 frame_id, | 144 void Shell::DidFinishLoad(int64 frame_id, |
| 145 const GURL& validated_url, | 145 const GURL& validated_url, |
| 146 bool is_main_frame) { | 146 bool is_main_frame) { |
| 147 if (!is_main_frame || wait_until_done_) | 147 if (!is_main_frame || wait_until_done_) |
| 148 return; | 148 return; |
| 149 if (!CommandLine::ForCurrentProcess()->HasSwitch(switches::kDumpRenderTree)) | 149 if (!CommandLine::ForCurrentProcess()->HasSwitch(switches::kDumpRenderTree)) |
| 150 return; | 150 return; |
| 151 RenderViewHostImpl* render_view_host = | 151 RenderViewHost* render_view_host = web_contents_->GetRenderViewHost(); |
| 152 static_cast<RenderViewHostImpl*>(tab_contents_->GetRenderViewHost()); | |
| 153 render_view_host->Send( | 152 render_view_host->Send( |
| 154 new ShellViewMsg_CaptureTextDump(render_view_host->GetRoutingID(), | 153 new ShellViewMsg_CaptureTextDump(render_view_host->GetRoutingID(), |
| 155 false)); | 154 false)); |
| 156 } | 155 } |
| 157 | 156 |
| 158 } // namespace content | 157 } // namespace content |
| OLD | NEW |