OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "blimp/engine/session/blimp_engine_session.h" | 5 #include "blimp/engine/session/blimp_engine_session.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/memory/ptr_util.h" | 10 #include "base/memory/ptr_util.h" |
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
222 gfx::Size(kDefaultDisplayWidth, | 222 gfx::Size(kDefaultDisplayWidth, |
223 kDefaultDisplayHeight)); | 223 kDefaultDisplayHeight)); |
224 render_widget_feature_.SetDelegate(kDummyTabId, this); | 224 render_widget_feature_.SetDelegate(kDummyTabId, this); |
225 } | 225 } |
226 | 226 |
227 BlimpEngineSession::~BlimpEngineSession() { | 227 BlimpEngineSession::~BlimpEngineSession() { |
228 render_widget_feature_.RemoveDelegate(kDummyTabId); | 228 render_widget_feature_.RemoveDelegate(kDummyTabId); |
229 | 229 |
230 window_tree_host_->GetInputMethod()->RemoveObserver(this); | 230 window_tree_host_->GetInputMethod()->RemoveObserver(this); |
231 | 231 |
| 232 page_load_tracker_.reset(); |
| 233 |
232 // Ensure that all WebContents are torn down first, since teardown will | 234 // Ensure that all WebContents are torn down first, since teardown will |
233 // trigger RenderViewDeleted callbacks to their observers. | 235 // trigger RenderViewDeleted callbacks to their observers. |
234 web_contents_.reset(); | 236 web_contents_.reset(); |
235 | 237 |
236 // Safely delete network components on the IO thread. | 238 // Safely delete network components on the IO thread. |
237 content::BrowserThread::DeleteSoon(content::BrowserThread::IO, FROM_HERE, | 239 content::BrowserThread::DeleteSoon(content::BrowserThread::IO, FROM_HERE, |
238 net_components_.release()); | 240 net_components_.release()); |
239 } | 241 } |
240 | 242 |
241 void BlimpEngineSession::Initialize() { | 243 void BlimpEngineSession::Initialize() { |
(...skipping 343 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
585 if (changed_flags & content::InvalidateTypes::INVALIDATE_TYPE_TITLE) | 587 if (changed_flags & content::InvalidateTypes::INVALIDATE_TYPE_TITLE) |
586 details->set_title(base::UTF16ToUTF8(source->GetTitle())); | 588 details->set_title(base::UTF16ToUTF8(source->GetTitle())); |
587 | 589 |
588 if (changed_flags & content::InvalidateTypes::INVALIDATE_TYPE_LOAD) | 590 if (changed_flags & content::InvalidateTypes::INVALIDATE_TYPE_LOAD) |
589 details->set_loading(source->IsLoading()); | 591 details->set_loading(source->IsLoading()); |
590 | 592 |
591 navigation_message_sender_->ProcessMessage(std::move(message), | 593 navigation_message_sender_->ProcessMessage(std::move(message), |
592 net::CompletionCallback()); | 594 net::CompletionCallback()); |
593 } | 595 } |
594 | 596 |
595 void BlimpEngineSession::LoadProgressChanged( | |
596 content::WebContents* source, double progress) { | |
597 if (source != web_contents_.get()) | |
598 return; | |
599 | |
600 bool page_load_completed = (progress == 1.0); | |
601 | |
602 // If the client has been notified of a page load completed change, avoid | |
603 // sending another message. For the first navigation, the initial value used | |
604 // by the client is already false. | |
605 if (last_page_load_completed_value_ == page_load_completed) | |
606 return; | |
607 | |
608 NavigationMessage* navigation_message = nullptr; | |
609 std::unique_ptr<BlimpMessage> message = | |
610 CreateBlimpMessage(&navigation_message, kDummyTabId); | |
611 navigation_message->set_type(NavigationMessage::NAVIGATION_STATE_CHANGED); | |
612 NavigationStateChangeMessage* details = | |
613 navigation_message->mutable_navigation_state_changed(); | |
614 details->set_page_load_completed(page_load_completed); | |
615 | |
616 navigation_message_sender_->ProcessMessage(std::move(message), | |
617 net::CompletionCallback()); | |
618 | |
619 last_page_load_completed_value_ = page_load_completed; | |
620 } | |
621 | |
622 void BlimpEngineSession::RenderViewCreated( | 597 void BlimpEngineSession::RenderViewCreated( |
623 content::RenderViewHost* render_view_host) { | 598 content::RenderViewHost* render_view_host) { |
624 render_widget_feature_.OnRenderWidgetCreated(kDummyTabId, | 599 render_widget_feature_.OnRenderWidgetCreated(kDummyTabId, |
625 render_view_host->GetWidget()); | 600 render_view_host->GetWidget()); |
626 } | 601 } |
627 | 602 |
628 void BlimpEngineSession::RenderViewHostChanged( | 603 void BlimpEngineSession::RenderViewHostChanged( |
629 content::RenderViewHost* old_host, | 604 content::RenderViewHost* old_host, |
630 content::RenderViewHost* new_host) { | 605 content::RenderViewHost* new_host) { |
631 // Informs client that WebContents swaps its visible RenderViewHost with | 606 // Informs client that WebContents swaps its visible RenderViewHost with |
632 // another one. | 607 // another one. |
633 render_widget_feature_.OnRenderWidgetInitialized(kDummyTabId, | 608 render_widget_feature_.OnRenderWidgetInitialized(kDummyTabId, |
634 new_host->GetWidget()); | 609 new_host->GetWidget()); |
635 } | 610 } |
636 | 611 |
637 void BlimpEngineSession::RenderViewDeleted( | 612 void BlimpEngineSession::RenderViewDeleted( |
638 content::RenderViewHost* render_view_host) { | 613 content::RenderViewHost* render_view_host) { |
639 render_widget_feature_.OnRenderWidgetDeleted(kDummyTabId, | 614 render_widget_feature_.OnRenderWidgetDeleted(kDummyTabId, |
640 render_view_host->GetWidget()); | 615 render_view_host->GetWidget()); |
641 } | 616 } |
642 | 617 |
| 618 void BlimpEngineSession::SendPageLoadStatusUpdate(PageLoadStatus load_status) { |
| 619 bool page_load_completed = false; |
| 620 |
| 621 switch (load_status) { |
| 622 case PageLoadStatus::LOADING: |
| 623 page_load_completed = false; |
| 624 break; |
| 625 case PageLoadStatus::LOADED: |
| 626 page_load_completed = true; |
| 627 break; |
| 628 } |
| 629 |
| 630 NavigationMessage* navigation_message = nullptr; |
| 631 std::unique_ptr<BlimpMessage> message = |
| 632 CreateBlimpMessage(&navigation_message, kDummyTabId); |
| 633 navigation_message->set_type(NavigationMessage::NAVIGATION_STATE_CHANGED); |
| 634 NavigationStateChangeMessage* details = |
| 635 navigation_message->mutable_navigation_state_changed(); |
| 636 details->set_page_load_completed(page_load_completed); |
| 637 |
| 638 navigation_message_sender_->ProcessMessage(std::move(message), |
| 639 net::CompletionCallback()); |
| 640 } |
| 641 |
643 void BlimpEngineSession::PlatformSetContents( | 642 void BlimpEngineSession::PlatformSetContents( |
644 std::unique_ptr<content::WebContents> new_contents) { | 643 std::unique_ptr<content::WebContents> new_contents) { |
645 new_contents->SetDelegate(this); | 644 new_contents->SetDelegate(this); |
646 Observe(new_contents.get()); | 645 Observe(new_contents.get()); |
647 web_contents_ = std::move(new_contents); | 646 web_contents_ = std::move(new_contents); |
648 | 647 |
| 648 page_load_tracker_.reset(new PageLoadTracker(web_contents_.get(), this)); |
649 aura::Window* parent = window_tree_host_->window(); | 649 aura::Window* parent = window_tree_host_->window(); |
650 aura::Window* content = web_contents_->GetNativeView(); | 650 aura::Window* content = web_contents_->GetNativeView(); |
651 if (!parent->Contains(content)) | 651 if (!parent->Contains(content)) |
652 parent->AddChild(content); | 652 parent->AddChild(content); |
653 content->Show(); | 653 content->Show(); |
654 } | 654 } |
655 | 655 |
656 } // namespace engine | 656 } // namespace engine |
657 } // namespace blimp | 657 } // namespace blimp |
OLD | NEW |