| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 "services/navigation/view_impl.h" | 5 #include "services/navigation/view_impl.h" |
| 6 | 6 |
| 7 #include "base/strings/utf_string_conversions.h" | 7 #include "base/strings/utf_string_conversions.h" |
| 8 #include "components/mus/public/cpp/window_tree_client.h" | 8 #include "components/mus/public/cpp/window_tree_client.h" |
| 9 #include "content/public/browser/interstitial_page.h" | 9 #include "content/public/browser/interstitial_page.h" |
| 10 #include "content/public/browser/interstitial_page_delegate.h" | 10 #include "content/public/browser/interstitial_page_delegate.h" |
| 11 #include "content/public/browser/navigation_controller.h" | 11 #include "content/public/browser/navigation_controller.h" |
| 12 #include "content/public/browser/navigation_details.h" |
| 13 #include "content/public/browser/navigation_entry.h" |
| 14 #include "content/public/browser/notification_details.h" |
| 15 #include "content/public/browser/notification_source.h" |
| 16 #include "content/public/browser/notification_types.h" |
| 12 #include "content/public/browser/web_contents.h" | 17 #include "content/public/browser/web_contents.h" |
| 13 #include "ui/views/controls/webview/webview.h" | 18 #include "ui/views/controls/webview/webview.h" |
| 14 #include "ui/views/mus/native_widget_mus.h" | 19 #include "ui/views/mus/native_widget_mus.h" |
| 15 #include "ui/views/widget/widget.h" | 20 #include "ui/views/widget/widget.h" |
| 16 #include "url/gurl.h" | 21 #include "url/gurl.h" |
| 17 | 22 |
| 18 namespace navigation { | 23 namespace navigation { |
| 19 namespace { | 24 namespace { |
| 20 | 25 |
| 21 class InterstitialPageDelegate : public content::InterstitialPageDelegate { | 26 class InterstitialPageDelegate : public content::InterstitialPageDelegate { |
| 22 public: | 27 public: |
| 23 explicit InterstitialPageDelegate(const std::string& html) : html_(html) {} | 28 explicit InterstitialPageDelegate(const std::string& html) : html_(html) {} |
| 24 ~InterstitialPageDelegate() override {} | 29 ~InterstitialPageDelegate() override {} |
| 25 InterstitialPageDelegate(const InterstitialPageDelegate&) = delete; | 30 InterstitialPageDelegate(const InterstitialPageDelegate&) = delete; |
| 26 void operator=(const InterstitialPageDelegate&) = delete; | 31 void operator=(const InterstitialPageDelegate&) = delete; |
| 27 | 32 |
| 28 private: | 33 private: |
| 29 | 34 |
| 30 // content::InterstitialPageDelegate: | 35 // content::InterstitialPageDelegate: |
| 31 std::string GetHTMLContents() override { | 36 std::string GetHTMLContents() override { |
| 32 return html_; | 37 return html_; |
| 33 } | 38 } |
| 34 | 39 |
| 35 const std::string html_; | 40 const std::string html_; |
| 36 }; | 41 }; |
| 37 | 42 |
| 43 // TODO(beng): Explicitly not writing a TypeConverter for this, and not doing a |
| 44 // typemap just yet since I'm still figuring out what these |
| 45 // interfaces should take as parameters. |
| 46 mojom::NavigationEntryPtr EntryPtrFromNavEntry( |
| 47 const content::NavigationEntry& entry) { |
| 48 mojom::NavigationEntryPtr entry_ptr(mojom::NavigationEntry::New()); |
| 49 entry_ptr->id = entry.GetUniqueID(); |
| 50 entry_ptr->url = entry.GetURL(); |
| 51 entry_ptr->title = base::UTF16ToUTF8(entry.GetTitle()); |
| 52 entry_ptr->redirect_chain = entry.GetRedirectChain(); |
| 53 return entry_ptr; |
| 54 } |
| 55 |
| 38 } // namespace | 56 } // namespace |
| 39 | 57 |
| 40 ViewImpl::ViewImpl(shell::Connector* connector, | 58 ViewImpl::ViewImpl(shell::Connector* connector, |
| 41 content::BrowserContext* browser_context, | 59 content::BrowserContext* browser_context, |
| 42 mojom::ViewClientPtr client, | 60 mojom::ViewClientPtr client, |
| 43 mojom::ViewRequest request, | 61 mojom::ViewRequest request, |
| 44 std::unique_ptr<shell::ShellConnectionRef> ref) | 62 std::unique_ptr<shell::ShellConnectionRef> ref) |
| 45 : connector_(connector), | 63 : connector_(connector), |
| 46 binding_(this, std::move(request)), | 64 binding_(this, std::move(request)), |
| 47 client_(std::move(client)), | 65 client_(std::move(client)), |
| 48 ref_(std::move(ref)), | 66 ref_(std::move(ref)), |
| 49 web_view_(new views::WebView(browser_context)) { | 67 web_view_(new views::WebView(browser_context)) { |
| 50 web_view_->GetWebContents()->SetDelegate(this); | 68 web_view_->GetWebContents()->SetDelegate(this); |
| 69 const content::NavigationController* controller = |
| 70 &web_view_->GetWebContents()->GetController(); |
| 71 registrar_.Add(this, content::NOTIFICATION_NAV_ENTRY_PENDING, |
| 72 content::Source<content::NavigationController>(controller)); |
| 73 registrar_.Add(this, content::NOTIFICATION_NAV_ENTRY_COMMITTED, |
| 74 content::Source<content::NavigationController>(controller)); |
| 75 registrar_.Add(this, content::NOTIFICATION_NAV_LIST_PRUNED, |
| 76 content::Source<content::NavigationController>(controller)); |
| 77 registrar_.Add(this, content::NOTIFICATION_NAV_ENTRY_CHANGED, |
| 78 content::Source<content::NavigationController>(controller)); |
| 51 } | 79 } |
| 52 ViewImpl::~ViewImpl() {} | 80 ViewImpl::~ViewImpl() {} |
| 53 | 81 |
| 54 void ViewImpl::NavigateTo(const GURL& url) { | 82 void ViewImpl::NavigateTo(const GURL& url) { |
| 55 web_view_->GetWebContents()->GetController().LoadURL( | 83 web_view_->GetWebContents()->GetController().LoadURL( |
| 56 url, content::Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); | 84 url, content::Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); |
| 57 } | 85 } |
| 58 | 86 |
| 59 void ViewImpl::GoBack() { | 87 void ViewImpl::GoBack() { |
| 60 web_view_->GetWebContents()->GetController().GoBack(); | 88 web_view_->GetWebContents()->GetController().GoBack(); |
| 61 } | 89 } |
| 62 | 90 |
| 63 void ViewImpl::GoForward() { | 91 void ViewImpl::GoForward() { |
| 64 web_view_->GetWebContents()->GetController().GoForward(); | 92 web_view_->GetWebContents()->GetController().GoForward(); |
| 65 } | 93 } |
| 66 | 94 |
| 95 void ViewImpl::NavigateToOffset(int offset) { |
| 96 web_view_->GetWebContents()->GetController().GoToOffset(offset); |
| 97 } |
| 98 |
| 67 void ViewImpl::Reload(bool skip_cache) { | 99 void ViewImpl::Reload(bool skip_cache) { |
| 68 if (skip_cache) | 100 if (skip_cache) |
| 69 web_view_->GetWebContents()->GetController().Reload(true); | 101 web_view_->GetWebContents()->GetController().Reload(true); |
| 70 else | 102 else |
| 71 web_view_->GetWebContents()->GetController().ReloadBypassingCache(true); | 103 web_view_->GetWebContents()->GetController().ReloadBypassingCache(true); |
| 72 } | 104 } |
| 73 | 105 |
| 74 void ViewImpl::Stop() { | 106 void ViewImpl::Stop() { |
| 75 web_view_->GetWebContents()->Stop(); | 107 web_view_->GetWebContents()->Stop(); |
| 76 } | 108 } |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 149 client_->UpdateHoverURL(url); | 181 client_->UpdateHoverURL(url); |
| 150 } | 182 } |
| 151 | 183 |
| 152 gfx::Rect ViewImpl::GetRootWindowResizerRect() const { | 184 gfx::Rect ViewImpl::GetRootWindowResizerRect() const { |
| 153 gfx::Rect bounds = web_view_->GetLocalBounds(); | 185 gfx::Rect bounds = web_view_->GetLocalBounds(); |
| 154 return gfx::Rect(bounds.right() - resizer_size_.width(), | 186 return gfx::Rect(bounds.right() - resizer_size_.width(), |
| 155 bounds.bottom() - resizer_size_.height(), | 187 bounds.bottom() - resizer_size_.height(), |
| 156 resizer_size_.width(), resizer_size_.height()); | 188 resizer_size_.width(), resizer_size_.height()); |
| 157 } | 189 } |
| 158 | 190 |
| 191 void ViewImpl::Observe(int type, |
| 192 const content::NotificationSource& source, |
| 193 const content::NotificationDetails& details) { |
| 194 DCHECK(content::Source<content::NavigationController>(source).ptr() == |
| 195 &web_view_->GetWebContents()->GetController()); |
| 196 switch (type) { |
| 197 case content::NOTIFICATION_NAV_ENTRY_PENDING: { |
| 198 const content::NavigationEntry* entry = |
| 199 content::Details<content::NavigationEntry>(details).ptr(); |
| 200 client_->NavigationPending(EntryPtrFromNavEntry(*entry)); |
| 201 break; |
| 202 } |
| 203 case content::NOTIFICATION_NAV_ENTRY_COMMITTED: { |
| 204 const content::LoadCommittedDetails* lcd = |
| 205 content::Details<content::LoadCommittedDetails>(details).ptr(); |
| 206 mojom::NavigationCommittedDetailsPtr details_ptr( |
| 207 mojom::NavigationCommittedDetails::New()); |
| 208 details_ptr->entry = lcd->entry->GetUniqueID(); |
| 209 details_ptr->type = static_cast<mojom::NavigationType>(lcd->type); |
| 210 details_ptr->previous_entry_index = lcd->previous_entry_index; |
| 211 details_ptr->previous_url = lcd->previous_url; |
| 212 details_ptr->is_in_page = lcd->is_in_page; |
| 213 details_ptr->is_main_frame = lcd->is_main_frame; |
| 214 details_ptr->http_status_code = lcd->http_status_code; |
| 215 client_->NavigationCommitted( |
| 216 std::move(details_ptr), |
| 217 web_view_->GetWebContents()->GetController().GetCurrentEntryIndex()); |
| 218 break; |
| 219 } |
| 220 case content::NOTIFICATION_NAV_ENTRY_CHANGED: { |
| 221 const content::EntryChangedDetails* ecd = |
| 222 content::Details<content::EntryChangedDetails>(details).ptr(); |
| 223 client_->NavigationEntryChanged(EntryPtrFromNavEntry(*ecd->changed_entry), |
| 224 ecd->index); |
| 225 break; |
| 226 } |
| 227 case content::NOTIFICATION_NAV_LIST_PRUNED: { |
| 228 const content::PrunedDetails* pd = |
| 229 content::Details<content::PrunedDetails>(details).ptr(); |
| 230 client_->NavigationListPruned(pd->from_front, pd->count); |
| 231 break; |
| 232 } |
| 233 default: |
| 234 NOTREACHED(); |
| 235 break; |
| 236 } |
| 237 } |
| 238 |
| 159 void ViewImpl::OnEmbed(mus::Window* root) { | 239 void ViewImpl::OnEmbed(mus::Window* root) { |
| 160 DCHECK(!widget_.get()); | 240 DCHECK(!widget_.get()); |
| 161 widget_.reset(new views::Widget); | 241 widget_.reset(new views::Widget); |
| 162 views::Widget::InitParams params( | 242 views::Widget::InitParams params( |
| 163 views::Widget::InitParams::TYPE_WINDOW_FRAMELESS); | 243 views::Widget::InitParams::TYPE_WINDOW_FRAMELESS); |
| 164 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; | 244 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; |
| 165 params.delegate = this; | 245 params.delegate = this; |
| 166 params.native_widget = new views::NativeWidgetMus( | 246 params.native_widget = new views::NativeWidgetMus( |
| 167 widget_.get(), connector_, root, mus::mojom::SurfaceType::DEFAULT); | 247 widget_.get(), connector_, root, mus::mojom::SurfaceType::DEFAULT); |
| 168 widget_->Init(params); | 248 widget_->Init(params); |
| 169 widget_->Show(); | 249 widget_->Show(); |
| 170 } | 250 } |
| 171 | 251 |
| 172 void ViewImpl::OnWindowTreeClientDestroyed(mus::WindowTreeClient* client) {} | 252 void ViewImpl::OnWindowTreeClientDestroyed(mus::WindowTreeClient* client) {} |
| 173 void ViewImpl::OnEventObserved(const ui::Event& event, mus::Window* target) {} | 253 void ViewImpl::OnEventObserved(const ui::Event& event, mus::Window* target) {} |
| 174 | 254 |
| 175 views::View* ViewImpl::GetContentsView() { | 255 views::View* ViewImpl::GetContentsView() { |
| 176 return web_view_; | 256 return web_view_; |
| 177 } | 257 } |
| 178 | 258 |
| 179 views::Widget* ViewImpl::GetWidget() { | 259 views::Widget* ViewImpl::GetWidget() { |
| 180 return web_view_->GetWidget(); | 260 return web_view_->GetWidget(); |
| 181 } | 261 } |
| 182 | 262 |
| 183 const views::Widget* ViewImpl::GetWidget() const { | 263 const views::Widget* ViewImpl::GetWidget() const { |
| 184 return web_view_->GetWidget(); | 264 return web_view_->GetWidget(); |
| 185 } | 265 } |
| 186 | 266 |
| 187 } // navigation | 267 } // navigation |
| OLD | NEW |