Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(405)

Unified Diff: components/dom_distiller/ios/distiller_page_ios.mm

Issue 2604773002: Create distiller files for Reading List. (Closed)
Patch Set: Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: components/dom_distiller/ios/distiller_page_ios.mm
diff --git a/components/dom_distiller/ios/distiller_page_ios.mm b/components/dom_distiller/ios/distiller_page_ios.mm
index 8ffacdfcbddcedc8bdfd58374cbbabd3db14747e..e54ff2481dbcb83beb2fe6bff8835516ab62d8c1 100644
--- a/components/dom_distiller/ios/distiller_page_ios.mm
+++ b/components/dom_distiller/ios/distiller_page_ios.mm
@@ -8,12 +8,14 @@
#include <utility>
+#include "base/bind.h"
#include "base/json/json_reader.h"
#include "base/logging.h"
#include "base/mac/foundation_util.h"
#include "base/memory/ptr_util.h"
#include "base/strings/sys_string_conversions.h"
#include "base/strings/utf_string_conversions.h"
+#include "base/threading/thread_task_runner_handle.h"
#include "base/values.h"
#include "components/favicon/ios/web_favicon_driver.h"
#include "ios/web/public/browser_state.h"
@@ -134,17 +136,33 @@ void DistillerWebStateObserver::WebStateDestroyed() {
#pragma mark -
-DistillerPageIOS::DistillerPageIOS(
- FaviconWebStateDispatcher* web_state_dispatcher)
- : web_state_dispatcher_(web_state_dispatcher), weak_ptr_factory_(this) {}
-
-DistillerPageIOS::~DistillerPageIOS() {
+DistillerPageIOS::DistillerPageIOS(std::unique_ptr<web::WebState> web_state)
+ : web_state_(std::move(web_state)), weak_ptr_factory_(this) {
+ if (web_state_) {
+ web_state_observer_ =
+ base::MakeUnique<DistillerWebStateObserver>(web_state_.get(), this);
+ }
}
bool DistillerPageIOS::StringifyOutput() {
return false;
}
+DistillerPageIOS::~DistillerPageIOS() {}
+
+std::unique_ptr<web::WebState> DistillerPageIOS::ReplaceWebState(
gambard 2016/12/27 09:35:58 I am not fond of this logic of switching web state
Olivier 2016/12/27 10:08:36 We need to update the observer. I am not sure how
+ std::unique_ptr<web::WebState> web_state) {
+ std::unique_ptr<web::WebState> old_web_state = std::move(web_state_);
+ web_state_ = std::move(web_state);
+ if (web_state_) {
+ web_state_observer_ =
+ base::MakeUnique<DistillerWebStateObserver>(web_state_.get(), this);
+ } else {
+ web_state_observer_.reset();
+ }
+ return old_web_state;
+}
+
void DistillerPageIOS::DistillPageImpl(const GURL& url,
const std::string& script) {
if (!url.is_valid() || !script.length())
@@ -152,21 +170,10 @@ void DistillerPageIOS::DistillPageImpl(const GURL& url,
url_ = url;
script_ = script;
- web_state_ = web_state_dispatcher_->RequestWebState();
-
if (!web_state_) {
OnLoadURLDone(web::PageLoadCompletionStatus::FAILURE);
return;
}
-
- web_state_observer_ =
- base::MakeUnique<DistillerWebStateObserver>(web_state_, this);
-
- // The favicon driver needs to know which URL is currently fetched.
- favicon::WebFaviconDriver* favicon_driver =
- favicon::WebFaviconDriver::FromWebState(web_state_);
- favicon_driver->FetchFavicon(url_);
gambard 2016/12/27 09:35:58 I don't see this code in the new version.
Olivier 2016/12/27 10:08:36 Done.
-
// Load page using WebState.
web::NavigationManager::WebLoadParams params(url_);
web_state_->SetWebUsageEnabled(true);
@@ -185,10 +192,13 @@ void DistillerPageIOS::OnLoadURLDone(
HandleJavaScriptResult(nil);
return;
}
-
- // Inject the script.
base::WeakPtr<DistillerPageIOS> weak_this = weak_ptr_factory_.GetWeakPtr();
-
+ base::ThreadTaskRunnerHandle::Get()->PostDelayedTask(
+ FROM_HERE, base::Bind(&DistillerPageIOS::DistillPage, weak_this),
+ base::TimeDelta::FromSeconds(2));
gambard 2016/12/27 09:35:58 Use a constant for the "2".
Olivier 2016/12/27 10:08:36 Code removed.
+}
+void DistillerPageIOS::DistillPage() {
+ base::WeakPtr<DistillerPageIOS> weak_this = weak_ptr_factory_.GetWeakPtr();
[[web_state_->GetJSInjectionReceiver()
instanceOfClass:[CRWJSInjectionManager class]]
executeJavaScript:base::SysUTF8ToNSString(script_)
@@ -200,8 +210,6 @@ void DistillerPageIOS::OnLoadURLDone(
}
void DistillerPageIOS::HandleJavaScriptResult(id result) {
- web_state_dispatcher_->ReturnWebState(web_state_);
- web_state_ = nullptr;
std::unique_ptr<base::Value> resultValue = base::Value::CreateNullValue();
if (result) {
resultValue = ValueResultFromScriptResult(result);

Powered by Google App Engine
This is Rietveld 408576698