blob: 8cde22f8583b2356a5f746d6760fe1e06ee45bcc (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
|
// Copyright (c) 2010 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/extensions/extension_clipboard_api.h"
#include "base/string_number_conversions.h"
#include "base/values.h"
#include "chrome/browser/extensions/extension_tabs_module.h"
#include "chrome/browser/renderer_host/render_view_host.h"
#include "chrome/browser/tab_contents/tab_contents.h"
#include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h"
#include "chrome/common/extensions/extension_error_utils.h"
namespace {
// Errors.
const char kNoTabError[] = "No tab with id: *.";
}
bool ClipboardFunction::RunImpl() {
int tab_id;
EXTENSION_FUNCTION_VALIDATE(args_->GetInteger(0, &tab_id));
TabContentsWrapper* contents = NULL;
if (!ExtensionTabUtil::GetTabById(tab_id, profile(), include_incognito(),
NULL, NULL, &contents, NULL)) {
error_ = ExtensionErrorUtils::FormatErrorMessage(
kNoTabError, base::IntToString(tab_id));
return false;
}
RenderViewHost* render_view_host = contents->render_view_host();
if (!render_view_host) {
return false;
}
return RunImpl(render_view_host);
}
bool ExecuteCopyClipboardFunction::RunImpl(RenderViewHost* render_view_host) {
render_view_host->Copy();
return true;
}
bool ExecuteCutClipboardFunction::RunImpl(RenderViewHost* render_view_host) {
render_view_host->Cut();
return true;
}
bool ExecutePasteClipboardFunction::RunImpl(RenderViewHost* render_view_host) {
render_view_host->Paste();
return true;
}
|