Skip to content

Commit

Permalink
DevTools: add experimental method for configuring the dock tile.
Browse files Browse the repository at this point in the history
This is an experimental feature that allows trusted remote debugging
clients such as Carlo adjust the dock tile details.

Change-Id: I7b263a14f1632d867c8bd3cffdd0527b3f3c96c9
Reviewed-on: https://chromium-review.googlesource.com/c/1337295
Commit-Queue: Dmitry Gozman <dgozman@chromium.org>
Reviewed-by: Dmitry Gozman <dgozman@chromium.org>
Cr-Commit-Position: refs/heads/master@{#608575}
  • Loading branch information
pavelfeldman authored and Commit Bot committed Nov 15, 2018
1 parent c5baed4 commit 8358f76
Show file tree
Hide file tree
Showing 11 changed files with 92 additions and 3 deletions.
7 changes: 6 additions & 1 deletion chrome/browser/devtools/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ static_library("devtools") {
"devtools_browser_context_manager.h",
"devtools_contents_resizing_strategy.cc",
"devtools_contents_resizing_strategy.h",
"devtools_dock_tile.h",
"devtools_embedder_message_dispatcher.cc",
"devtools_embedder_message_dispatcher.h",
"devtools_eye_dropper.cc",
Expand Down Expand Up @@ -185,7 +186,11 @@ static_library("devtools") {
]
}
}

if (is_mac) {
sources += [ "devtools_dock_tile_mac.mm" ]
} else {
sources += [ "devtools_dock_tile.cc" ]
}
if (!is_android) {
deps += [ ":protocol_generated_sources" ]
sources += [
Expand Down
8 changes: 8 additions & 0 deletions chrome/browser/devtools/devtools_dock_tile.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "chrome/browser/devtools/devtools_dock_tile.h"

// static
void DevToolsDockTile::Update(const std::string& label, gfx::Image image) {}
19 changes: 19 additions & 0 deletions chrome/browser/devtools/devtools_dock_tile.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// Copyright (c) 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef CHROME_BROWSER_DEVTOOLS_DEVTOOLS_DOCK_TILE_H_
#define CHROME_BROWSER_DEVTOOLS_DEVTOOLS_DOCK_TILE_H_

#include "base/macros.h"
#include "ui/gfx/image/image.h"

class DevToolsDockTile {
public:
static void Update(const std::string& label, gfx::Image image);

private:
DISALLOW_COPY_AND_ASSIGN(DevToolsDockTile);
};

#endif // CHROME_BROWSER_DEVTOOLS_DEVTOOLS_DOCK_TILE_H_
25 changes: 25 additions & 0 deletions chrome/browser/devtools/devtools_dock_tile_mac.mm
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "base/mac/scoped_nsobject.h"
#include "base/strings/sys_string_conversions.h"
#include "chrome/browser/devtools/devtools_dock_tile.h"

#import <Cocoa/Cocoa.h>

// static
void DevToolsDockTile::Update(const std::string& label, gfx::Image image) {
NSDockTile* dockTile = [[NSApplication sharedApplication] dockTile];
if (!image.IsEmpty()) {
NSRect imageFrame = NSMakeRect(0, 0, 0, 0);
base::scoped_nsobject<NSImageView> imageView(
[[NSImageView alloc] initWithFrame:imageFrame]);
NSImage* nsImage = image.ToNSImage();
[imageView setImage:nsImage];
[dockTile setContentView:imageView];
}
if (!label.empty())
[dockTile setBadgeLabel:base::SysUTF8ToNSString(label)];
[dockTile display];
}
2 changes: 1 addition & 1 deletion chrome/browser/devtools/inspector_protocol_config.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
},
{
"domain": "Browser",
"include": [ "getWindowForTarget", "getWindowBounds", "setWindowBounds", "close", "grantPermissions", "resetPermissions" ],
"include": [ "getWindowForTarget", "getWindowBounds", "setWindowBounds", "close", "grantPermissions", "resetPermissions", "setDockTile" ],
"include_events": []
},
{
Expand Down
16 changes: 16 additions & 0 deletions chrome/browser/devtools/protocol/browser_handler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,12 @@
#include "chrome/browser/devtools/protocol/browser_handler.h"

#include <set>
#include <vector>

#include "base/memory/ref_counted_memory.h"
#include "base/task/post_task.h"
#include "chrome/browser/devtools/chrome_devtools_manager_delegate.h"
#include "chrome/browser/devtools/devtools_dock_tile.h"
#include "chrome/browser/lifetime/application_lifetime.h"
#include "chrome/browser/permissions/permission_manager.h"
#include "chrome/browser/profiles/profile.h"
Expand All @@ -18,6 +21,8 @@
#include "content/public/browser/browser_task_traits.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/devtools_agent_host.h"
#include "ui/gfx/image/image.h"
#include "ui/gfx/image/image_png_rep.h"

using PermissionOverrides = std::set<content::PermissionType>;
using protocol::Maybe;
Expand Down Expand Up @@ -275,6 +280,17 @@ Response BrowserHandler::ResetPermissions(
return Response::FallThrough();
}

protocol::Response BrowserHandler::SetDockTile(
protocol::Maybe<std::string> label,
protocol::Maybe<protocol::Binary> image) {
std::vector<gfx::ImagePNGRep> reps;
if (image.isJust())
reps.emplace_back(image.fromJust().bytes(), 1);
DevToolsDockTile::Update(label.fromMaybe(std::string()),
reps.size() ? gfx::Image(reps) : gfx::Image());
return Response::OK();
}

Response BrowserHandler::FindProfile(
const Maybe<std::string>& browser_context_id,
Profile** profile) {
Expand Down
3 changes: 3 additions & 0 deletions chrome/browser/devtools/protocol/browser_handler.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ class BrowserHandler : public protocol::Browser::Backend {
protocol::Maybe<std::string> browser_context_id) override;
protocol::Response ResetPermissions(
protocol::Maybe<std::string> browser_context_id) override;
protocol::Response SetDockTile(
protocol::Maybe<std::string> label,
protocol::Maybe<protocol::Binary> image) override;

private:
protocol::Response FindProfile(
Expand Down
5 changes: 5 additions & 0 deletions headless/lib/browser/protocol/browser_handler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -112,5 +112,10 @@ Response BrowserHandler::SetWindowBounds(
return Response::OK();
}

protocol::Response BrowserHandler::SetDockTile(Maybe<std::string> label,
Maybe<protocol::Binary> image) {
return Response::OK();
}

} // namespace protocol
} // namespace headless
1 change: 1 addition & 0 deletions headless/lib/browser/protocol/browser_handler.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ class BrowserHandler : public DomainHandler, public Browser::Backend {
Response SetWindowBounds(
int window_id,
std::unique_ptr<Browser::Bounds> out_bounds) override;
Response SetDockTile(Maybe<std::string> label, Maybe<Binary> image) override;

private:
std::string target_id_;
Expand Down
2 changes: 1 addition & 1 deletion headless/protocol_config.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
},
{
"domain": "Browser",
"include": ["close", "getWindowForTarget", "getWindowBounds", "setWindowBounds" ],
"include": ["close", "getWindowForTarget", "getWindowBounds", "setWindowBounds", "setDockTile" ],
"include_events": []
},
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -635,6 +635,13 @@ domain Browser
# with 'left', 'top', 'width' or 'height'. Leaves unspecified fields unchanged.
Bounds bounds

# Set dock tile details, platform-specific.
experimental command setDockTile
parameters
optional string badgeLabel
# Png encoded image.
optional binary image

# This domain exposes CSS read/write operations. All CSS objects (stylesheets, rules, and styles)
# have an associated `id` used in subsequent operations on the related object. Each object type has
# a specific `id` structure, and those are not interchangeable between objects of different kinds.
Expand Down

0 comments on commit 8358f76

Please sign in to comment.