summaryrefslogtreecommitdiffstats
path: root/extensions/browser/view_type_utils.cc
blob: 933d669037df52c4eeb1fcee9c326456df037f34 (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
// Copyright (c) 2012 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 "extensions/browser/view_type_utils.h"

#include "base/lazy_instance.h"
#include "content/public/browser/web_contents.h"
#include "extensions/browser/extensions_browser_client.h"

using content::WebContents;

namespace extensions {

namespace {

const char kViewTypeUserDataKey[] = "ViewTypeUserData";

class ViewTypeUserData : public base::SupportsUserData::Data {
 public:
  explicit ViewTypeUserData(ViewType type) : type_(type) {}
  ~ViewTypeUserData() override {}
  ViewType type() { return type_; }

 private:
  ViewType type_;
};

}  // namespace

ViewType GetViewType(WebContents* tab) {
  if (!tab)
    return VIEW_TYPE_INVALID;

  ViewTypeUserData* user_data = static_cast<ViewTypeUserData*>(
      tab->GetUserData(&kViewTypeUserDataKey));

  return user_data ? user_data->type() : VIEW_TYPE_INVALID;
}

void SetViewType(WebContents* tab, ViewType type) {
  tab->SetUserData(&kViewTypeUserDataKey, new ViewTypeUserData(type));

  ExtensionsBrowserClient::Get()->AttachExtensionTaskManagerTag(tab, type);
}

}  // namespace extensions