Commit 1f808902 authored by Dmitry Gozman's avatar Dmitry Gozman Committed by Commit Bot

Move manifest handling from DevToolsAgent to PageHandler

The API is now accessible from browser, so there is no need
for special handling in renderer.
This unblocks moving DevToolsAgent to blink.

Bug: 776009
Change-Id: Ie2b96e2fa99a613cbc26ec6703afe7d940d3d3c8
Reviewed-on: https://chromium-review.googlesource.com/828292
Commit-Queue: Dmitry Gozman <dgozman@chromium.org>
Reviewed-by: default avatarPavel Feldman <pfeldman@chromium.org>
Cr-Commit-Position: refs/heads/master@{#524500}
parent c3046bd3
...@@ -26,6 +26,7 @@ ...@@ -26,6 +26,7 @@
#include "content/browser/devtools/protocol/devtools_download_manager_helper.h" #include "content/browser/devtools/protocol/devtools_download_manager_helper.h"
#include "content/browser/devtools/protocol/emulation_handler.h" #include "content/browser/devtools/protocol/emulation_handler.h"
#include "content/browser/frame_host/navigation_request.h" #include "content/browser/frame_host/navigation_request.h"
#include "content/browser/manifest/manifest_manager_host.h"
#include "content/browser/renderer_host/render_widget_host_impl.h" #include "content/browser/renderer_host/render_widget_host_impl.h"
#include "content/browser/renderer_host/render_widget_host_view_base.h" #include "content/browser/renderer_host/render_widget_host_view_base.h"
#include "content/browser/web_contents/web_contents_impl.h" #include "content/browser/web_contents/web_contents_impl.h"
...@@ -737,6 +738,18 @@ Response PageHandler::SetDownloadBehavior(const std::string& behavior, ...@@ -737,6 +738,18 @@ Response PageHandler::SetDownloadBehavior(const std::string& behavior,
return Response::OK(); return Response::OK();
} }
void PageHandler::GetAppManifest(
std::unique_ptr<GetAppManifestCallback> callback) {
WebContentsImpl* web_contents = GetWebContents();
if (!web_contents || !web_contents->GetManifestManagerHost()) {
callback->sendFailure(Response::Error("Cannot retrieve manifest"));
return;
}
web_contents->GetManifestManagerHost()->RequestManifestDebugInfo(
base::BindOnce(&PageHandler::GotManifest, weak_factory_.GetWeakPtr(),
std::move(callback)));
}
WebContentsImpl* PageHandler::GetWebContents() { WebContentsImpl* PageHandler::GetWebContents() {
return host_ ? return host_ ?
static_cast<WebContentsImpl*>(WebContents::FromRenderFrameHost(host_)) : static_cast<WebContentsImpl*>(WebContents::FromRenderFrameHost(host_)) :
...@@ -902,6 +915,30 @@ void PageHandler::ScreenshotCaptured( ...@@ -902,6 +915,30 @@ void PageHandler::ScreenshotCaptured(
} }
} }
void PageHandler::GotManifest(std::unique_ptr<GetAppManifestCallback> callback,
const GURL& manifest_url,
blink::mojom::ManifestDebugInfoPtr debug_info) {
std::unique_ptr<Array<Page::AppManifestError>> errors =
Array<Page::AppManifestError>::create();
bool failed = true;
if (debug_info) {
failed = false;
for (const auto& error : debug_info->errors) {
errors->addItem(Page::AppManifestError::Create()
.SetMessage(error->message)
.SetCritical(error->critical)
.SetLine(error->line)
.SetColumn(error->column)
.Build());
if (error->critical)
failed = true;
}
}
callback->sendSuccess(
manifest_url.possibly_invalid_spec(), std::move(errors),
failed ? Maybe<std::string>() : debug_info->raw_manifest);
}
Response PageHandler::StopLoading() { Response PageHandler::StopLoading() {
WebContentsImpl* web_contents = GetWebContents(); WebContentsImpl* web_contents = GetWebContents();
if (!web_contents) if (!web_contents)
......
...@@ -25,6 +25,7 @@ ...@@ -25,6 +25,7 @@
#include "content/public/browser/notification_registrar.h" #include "content/public/browser/notification_registrar.h"
#include "content/public/browser/readback_types.h" #include "content/public/browser/readback_types.h"
#include "content/public/common/javascript_dialog_type.h" #include "content/public/common/javascript_dialog_type.h"
#include "third_party/WebKit/public/platform/modules/manifest/manifest_manager.mojom.h"
#include "url/gurl.h" #include "url/gurl.h"
class SkBitmap; class SkBitmap;
...@@ -136,6 +137,9 @@ class PageHandler : public DevToolsDomainHandler, ...@@ -136,6 +137,9 @@ class PageHandler : public DevToolsDomainHandler,
Response SetDownloadBehavior(const std::string& behavior, Response SetDownloadBehavior(const std::string& behavior,
Maybe<std::string> download_path) override; Maybe<std::string> download_path) override;
void GetAppManifest(
std::unique_ptr<GetAppManifestCallback> callback) override;
private: private:
enum EncodingFormat { PNG, JPEG }; enum EncodingFormat { PNG, JPEG };
...@@ -158,6 +162,10 @@ class PageHandler : public DevToolsDomainHandler, ...@@ -158,6 +162,10 @@ class PageHandler : public DevToolsDomainHandler,
const blink::WebDeviceEmulationParams& original_params, const blink::WebDeviceEmulationParams& original_params,
const gfx::Image& image); const gfx::Image& image);
void GotManifest(std::unique_ptr<GetAppManifestCallback> callback,
const GURL& manifest_url,
blink::mojom::ManifestDebugInfoPtr debug_info);
// NotificationObserver overrides. // NotificationObserver overrides.
void Observe(int type, void Observe(int type,
const NotificationSource& source, const NotificationSource& source,
......
...@@ -48,9 +48,9 @@ ...@@ -48,9 +48,9 @@
"domain": "Page", "domain": "Page",
"include": ["enable", "disable", "reload", "navigate", "stopLoading", "getNavigationHistory", "navigateToHistoryEntry", "captureScreenshot", "include": ["enable", "disable", "reload", "navigate", "stopLoading", "getNavigationHistory", "navigateToHistoryEntry", "captureScreenshot",
"startScreencast", "stopScreencast", "screencastFrameAck", "handleJavaScriptDialog", "setColorPickerEnabled", "requestAppBanner", "startScreencast", "stopScreencast", "screencastFrameAck", "handleJavaScriptDialog", "setColorPickerEnabled", "requestAppBanner",
"printToPDF", "bringToFront", "setDownloadBehavior"], "printToPDF", "bringToFront", "setDownloadBehavior", "getAppManifest"],
"include_events": ["colorPicked", "interstitialShown", "interstitialHidden", "javascriptDialogOpening", "javascriptDialogClosed", "screencastVisibilityChanged", "screencastFrame"], "include_events": ["colorPicked", "interstitialShown", "interstitialHidden", "javascriptDialogOpening", "javascriptDialogClosed", "screencastVisibilityChanged", "screencastFrame"],
"async": ["captureScreenshot", "printToPDF", "navigate"] "async": ["captureScreenshot", "printToPDF", "navigate", "getAppManifest"]
}, },
{ {
"domain": "Runtime", "domain": "Runtime",
......
...@@ -39,6 +39,11 @@ void ManifestManagerHost::GetManifest(const GetManifestCallback& callback) { ...@@ -39,6 +39,11 @@ void ManifestManagerHost::GetManifest(const GetManifestCallback& callback) {
base::Unretained(this), request_id)); base::Unretained(this), request_id));
} }
void ManifestManagerHost::RequestManifestDebugInfo(
blink::mojom::ManifestManager::RequestManifestDebugInfoCallback callback) {
GetManifestManager().RequestManifestDebugInfo(std::move(callback));
}
blink::mojom::ManifestManager& ManifestManagerHost::GetManifestManager() { blink::mojom::ManifestManager& ManifestManagerHost::GetManifestManager() {
if (manifest_manager_frame_ != web_contents()->GetMainFrame()) if (manifest_manager_frame_ != web_contents()->GetMainFrame())
OnConnectionError(); OnConnectionError();
......
...@@ -37,6 +37,9 @@ class ManifestManagerHost : public WebContentsObserver, ...@@ -37,6 +37,9 @@ class ManifestManagerHost : public WebContentsObserver,
// have an empty manifest. // have an empty manifest.
void GetManifest(const GetManifestCallback& callback); void GetManifest(const GetManifestCallback& callback);
void RequestManifestDebugInfo(
blink::mojom::ManifestManager::RequestManifestDebugInfoCallback callback);
// WebContentsObserver // WebContentsObserver
void RenderFrameDeleted(RenderFrameHost* render_frame_host) override; void RenderFrameDeleted(RenderFrameHost* render_frame_host) override;
......
...@@ -285,6 +285,10 @@ class CONTENT_EXPORT WebContentsImpl : public WebContents, ...@@ -285,6 +285,10 @@ class CONTENT_EXPORT WebContentsImpl : public WebContents,
void NotifyManifestUrlChanged(const base::Optional<GURL>& manifest_url); void NotifyManifestUrlChanged(const base::Optional<GURL>& manifest_url);
ManifestManagerHost* GetManifestManagerHost() const {
return manifest_manager_host_.get();
}
#if defined(OS_ANDROID) #if defined(OS_ANDROID)
std::set<RenderWidgetHostImpl*> GetAllRenderWidgetHosts(); std::set<RenderWidgetHostImpl*> GetAllRenderWidgetHosts();
void SetImportance(ChildProcessImportance importance); void SetImportance(ChildProcessImportance importance);
......
...@@ -42,7 +42,6 @@ namespace { ...@@ -42,7 +42,6 @@ namespace {
// TODO(dgozman): somehow get this from a mojo config. // TODO(dgozman): somehow get this from a mojo config.
// See kMaximumMojoMessageSize in services/service_manager/embedder/main.cc. // See kMaximumMojoMessageSize in services/service_manager/embedder/main.cc.
const size_t kMaxDevToolsMessageChunkSize = 128 * 1024 * 1024 / 4; const size_t kMaxDevToolsMessageChunkSize = 128 * 1024 * 1024 / 4;
const char kPageGetAppManifest[] = "Page.getAppManifest";
} // namespace } // namespace
...@@ -279,12 +278,6 @@ void DevToolsAgent::DispatchOnInspectorBackend(int session_id, ...@@ -279,12 +278,6 @@ void DevToolsAgent::DispatchOnInspectorBackend(int session_id,
const std::string& method, const std::string& method,
const std::string& message) { const std::string& message) {
TRACE_EVENT0("devtools", "DevToolsAgent::DispatchOnInspectorBackend"); TRACE_EVENT0("devtools", "DevToolsAgent::DispatchOnInspectorBackend");
if (method == kPageGetAppManifest) {
frame_->GetManifestManager().RequestManifestDebugInfo(
base::BindOnce(&DevToolsAgent::GotManifest, weak_factory_.GetWeakPtr(),
session_id, call_id));
return;
}
GetWebAgent()->DispatchOnInspectorBackend(session_id, call_id, GetWebAgent()->DispatchOnInspectorBackend(session_id, call_id,
WebString::FromUTF8(method), WebString::FromUTF8(method),
WebString::FromUTF8(message)); WebString::FromUTF8(message));
...@@ -330,40 +323,4 @@ void DevToolsAgent::DetachAllSessions() { ...@@ -330,40 +323,4 @@ void DevToolsAgent::DetachAllSessions() {
sessions_.clear(); sessions_.clear();
} }
void DevToolsAgent::GotManifest(int session_id,
int call_id,
const GURL& manifest_url,
blink::mojom::ManifestDebugInfoPtr debug_info) {
std::unique_ptr<base::DictionaryValue> response(new base::DictionaryValue());
response->SetInteger("id", call_id);
std::unique_ptr<base::DictionaryValue> result(new base::DictionaryValue());
std::unique_ptr<base::ListValue> errors(new base::ListValue());
bool failed = false;
if (debug_info) {
for (const auto& error : debug_info->errors) {
std::unique_ptr<base::DictionaryValue> error_value(
new base::DictionaryValue());
error_value->SetString("message", error->message);
error_value->SetBoolean("critical", error->critical);
error_value->SetInteger("line", error->line);
error_value->SetInteger("column", error->column);
if (error->critical)
failed = true;
errors->Append(std::move(error_value));
}
if (!failed)
result->SetString("data", debug_info->raw_manifest);
}
result->SetString("url", manifest_url.possibly_invalid_spec());
result->Set("errors", std::move(errors));
response->Set("result", std::move(result));
std::string json_message;
base::JSONWriter::Write(*response, &json_message);
SendChunkedProtocolMessage(session_id, call_id, std::move(json_message),
std::string());
}
} // namespace content } // namespace content
...@@ -17,15 +17,12 @@ ...@@ -17,15 +17,12 @@
#include "content/common/devtools.mojom.h" #include "content/common/devtools.mojom.h"
#include "content/public/renderer/render_frame_observer.h" #include "content/public/renderer/render_frame_observer.h"
#include "mojo/public/cpp/bindings/associated_binding.h" #include "mojo/public/cpp/bindings/associated_binding.h"
#include "third_party/WebKit/public/platform/modules/manifest/manifest.mojom.h"
#include "third_party/WebKit/public/web/WebDevToolsAgentClient.h" #include "third_party/WebKit/public/web/WebDevToolsAgentClient.h"
namespace blink { namespace blink {
class WebDevToolsAgent; class WebDevToolsAgent;
} }
class GURL;
namespace content { namespace content {
class RenderFrameImpl; class RenderFrameImpl;
...@@ -80,10 +77,6 @@ class CONTENT_EXPORT DevToolsAgent : public RenderFrameObserver, ...@@ -80,10 +77,6 @@ class CONTENT_EXPORT DevToolsAgent : public RenderFrameObserver,
const std::string& message); const std::string& message);
void InspectElement(int session_id, const gfx::Point& point); void InspectElement(int session_id, const gfx::Point& point);
void OnRequestNewWindowCompleted(int session_id, bool success); void OnRequestNewWindowCompleted(int session_id, bool success);
void GotManifest(int session_id,
int command_id,
const GURL& manifest_url,
blink::mojom::ManifestDebugInfoPtr debug_info);
void SendChunkedProtocolMessage(int session_id, void SendChunkedProtocolMessage(int session_id,
int call_id, int call_id,
std::string message, std::string message,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment