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 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145
|
// Copyright 2018 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROME_BROWSER_NOTIFICATIONS_WIN_NOTIFICATION_LAUNCH_ID_H_
#define CHROME_BROWSER_NOTIFICATIONS_WIN_NOTIFICATION_LAUNCH_ID_H_
#include <string>
#include "base/command_line.h"
#include "base/files/file_path.h"
#include "chrome/browser/notifications/notification_handler.h"
#include "url/gurl.h"
// This class encapsulates the launch id strings that are passed back and forth
// between Chrome and the Windows Action Center and contain the necessary info
// to figure out which notification was activated in the Action Center.
class NotificationLaunchId {
public:
NotificationLaunchId();
NotificationLaunchId(const NotificationLaunchId& other);
// `notification_id` and `profile_id` must be UTF8 strings.
NotificationLaunchId(NotificationHandler::Type notification_type,
const std::string& notification_id,
const std::string& profile_id,
const std::wstring& app_user_model_id,
bool incognito,
const GURL& origin_url);
// A constructor used to parse an encoded string we get back from the Action
// Center. Callers must use is_valid() to check if decoding was successful.
explicit NotificationLaunchId(const std::string& encoded);
~NotificationLaunchId();
NotificationLaunchId& operator=(const NotificationLaunchId& other) = default;
bool is_valid() const { return is_valid_; }
std::string Serialize() const;
void set_button_index(int index) {
DCHECK(!is_for_context_menu_);
button_index_ = index;
}
void set_is_for_context_menu() {
DCHECK_EQ(-1, button_index_);
is_for_context_menu_ = true;
}
void set_is_for_dismiss_button() {
DCHECK_EQ(-1, button_index_);
is_for_dismiss_button_ = true;
}
NotificationHandler::Type notification_type() const {
DCHECK(is_valid());
return notification_type_;
}
const std::string& notification_id() const {
DCHECK(is_valid());
return notification_id_;
}
const std::string& profile_id() const {
DCHECK(is_valid());
return profile_id_;
}
const std::wstring& app_user_model_id() const {
DCHECK(is_valid());
return app_user_model_id_;
}
bool incognito() const {
DCHECK(is_valid());
return incognito_;
}
const GURL& origin_url() const {
DCHECK(is_valid());
return origin_url_;
}
int button_index() const {
DCHECK(is_valid());
return button_index_;
}
bool is_for_context_menu() const {
DCHECK(is_valid());
return is_for_context_menu_;
}
bool is_for_dismiss_button() const {
DCHECK(is_valid());
return is_for_dismiss_button_;
}
// Extracts the profile ID from |launch_id_str|.
static std::string GetProfileIdFromLaunchId(
const std::wstring& launch_id_str);
// Retrieves the profile basename from the notification launch command line,
// if any.
static base::FilePath GetNotificationLaunchProfileBaseName(
const base::CommandLine& command_line);
private:
// The notification type this launch ID is associated with.
NotificationHandler::Type notification_type_;
// The notification id this launch ID is associated with. The string is UTF8.
std::string notification_id_;
// The profile id this launch ID is associated with. The string is UTF8.
std::string profile_id_;
// The app user model id this launch ID is associated with.
std::wstring app_user_model_id_;
// A flag indicating if the notification associated with this launch ID is in
// incognito mode or not.
bool incognito_ = false;
// The original URL this launch ID is associated with.
GURL origin_url_;
// The button index this launch ID is associated with.
int button_index_ = -1;
// A flag indicating if this launch ID is targeting the context menu or not.
bool is_for_context_menu_ = false;
// A flag indicating if this launch ID is targeting the dismiss button or not.
bool is_for_dismiss_button_ = false;
// A flag indicating if this launch ID is valid.
bool is_valid_ = false;
};
#endif // CHROME_BROWSER_NOTIFICATIONS_WIN_NOTIFICATION_LAUNCH_ID_H_
|